天天看點

小白Intellij IDEA 搭建Spring Boot項目Intellij IDEA 搭建Spring Boot項目

這裡寫自定義目錄标題

  • Intellij IDEA 搭建Spring Boot項目
    • **等等。還沒結束,接下來講一下我踩的坑。

Intellij IDEA 搭建Spring Boot項目

第一步

選擇File –> New –> Project –>Spring Initialer –> 點選Next

小白Intellij IDEA 搭建Spring Boot項目Intellij IDEA 搭建Spring Boot項目

第二步

自己修改 Group 和 Artifact 字段名 –>點選next

artifact相當于工程的名字了,好好起一個合适的

小白Intellij IDEA 搭建Spring Boot項目Intellij IDEA 搭建Spring Boot項目

第三步

我的Spring boot是沒有圖檔原文上面的那個版本,于是就選擇了預設的那個,也不影響什麼的

還勾選了sql->mybaties,為之後連接配接資料庫做準備

小白Intellij IDEA 搭建Spring Boot項目Intellij IDEA 搭建Spring Boot項目

第四步

我的項目名字和之前的artifact設的同一個,項目所在位址這個,如果是在idea一個已有的項目裡面選擇的建立,可能會預設定位到那個項目的子路徑,需要調整到最外層。

點選finish

小白Intellij IDEA 搭建Spring Boot項目Intellij IDEA 搭建Spring Boot項目

第五步

等待編譯完成,會很慢,耐心等待

。。。。。。。。。。

第六步

删除這三個檔案,我也不知道原因,删就對了

小白Intellij IDEA 搭建Spring Boot項目Intellij IDEA 搭建Spring Boot項目

第七步(最終目錄結構)

可以大家檢查一下

小白Intellij IDEA 搭建Spring Boot項目Intellij IDEA 搭建Spring Boot項目

第八步

**在src->main->java->com.rolan.springtest下建一個package名字為controller,在這個controller下面建立一個HelloController.java(**注意是.java檔案,預設建出來的是.class,以後可能有問題,如果是.clsss,需要改成.java)

編輯HelloController類用于轉發連結,提示缺什麼就alt+enter, import就可以了

以下為HelloController類内容

起:

@RestController

@EnableAutoConfiguration

public class HelloController {

@RequestMapping("/hello")

private String index(){

return “Hello World!”;

}

}

至。

第九步

啟動項目

![在這裡插入圖檔描述](https://img-blog.csdnimg.cn/20190515115536360.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NDAxMjcyMQ==,size_16,color_FFFFFF,t_70

啟動之後可以看控制台顯示的是如下:

小白Intellij IDEA 搭建Spring Boot項目Intellij IDEA 搭建Spring Boot項目

我們在浏覽器中輸入如下的http://localhost:8080/hello –>顯示的如下界面代表我們項目成功了

小白Intellij IDEA 搭建Spring Boot項目Intellij IDEA 搭建Spring Boot項目

**等等。還沒結束,接下來講一下我踩的坑。

1.我比參考原文多選擇了mysql->mybaties,在運作時會報資料庫的錯誤。

解決:去下圖的地方,陰影選中的語句進行替換,就是在@SpringBootApplication後面加上(exclude= {DataSourceAutoConfiguration.class})**

小白Intellij IDEA 搭建Spring Boot項目Intellij IDEA 搭建Spring Boot項目

2.Spring boot預設端口是8080,很容易被占用,建議去修改一下端口号,我更改為了9090,更改方式為下圖:

小白Intellij IDEA 搭建Spring Boot項目Intellij IDEA 搭建Spring Boot項目

祝大家好運呀,一起加油!

參考原文:https://blog.csdn.net/wuyinlei/article/details/79227962

加粗的均為部落客原創加工部分。

繼續閱讀