🍅程式員小王的博客:程式員小王的博客
🍅 歡迎點贊 👍 收藏 ?留言 📝
🍅 如有編輯錯誤聯系作者,如果有比較好的文章歡迎分享給我,我會取其精華去其糟粕
🍅java自學的學習路線:java自學的學習路線
- Springboot的優點
約定大于配置 ; 幫我們自動配置了我們需要配置的內容; 并且幫我們自動下載了需要下載的jar包以及運行環境;
優點: 方便,作為初學者來說直接使用就可以了;
缺點: 出現問題,我們作為初學者很難去定位解決;
一、idea手工搭建SpringBoot專案
1、點擊file==>點擊new==>moudle

2、選擇maven==>勾選Create from archetype==>maven-archetype-webapp==>下一步

3、根據圖設定之后點擊下一步

4、點擊下一步

5、手工創建后的初始結構

6、右擊src==>點擊new==>directory

7、選擇圖片中的所有

8、修改后的專案結構圖

9、修改pom.xml配置依賴檔案
(1)洗掉所有build包含的標簽

(2)繼承springboot父專案,引入web,test相關依賴
<groupId>com.tjcu</groupId>
<artifactId>handwork_SpringBoot</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<!--1.繼承springboot父專案-->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.5.RELEASE</version>
</parent>
<dependencies>
<!--spring-boot-stater-web-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!--引入springboot-stater-test-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<!--scope test 僅僅在測驗時有效 運行 打包 不生效-->
<scope>test</scope>
</dependency>
</dependencies>
10、創建application.properties檔案
專案中src/main/resources/application.yml

11、創建入口類函式
@SpringBootApplication
public class Application {
public static void main(String[] args) {
/**
* 入口類函式
*/
SpringApplication.run(Application.class,args);
}
}

12、創建控制層
@RequestMapping("/user")
public class HandworkDemo {
/**
*@ResponseBody:將控制器回傳值轉化為json格式字串 并回應瀏覽器
* @return
*/
@RequestMapping("create")
@ResponseBody
public String createName(){
String name="王恒杰實作手工創建SpringBoot專案結構搭建!";
return name;
}
}

13、運行main啟動專案
(1)啟動專案

(2)啟動專案成功后

14、訪問專案
二、idea自動搭建SpringBoot專案
1、創建SpringBoot專案
- 注意:server URL使用阿里云:
start.aliyun.com

2、設定我們的專案名稱等內容

3、匯入SpringMVC的jar包

4、選擇模板引擎

5、選擇關系型資料庫操作的mybatis以及我們的mysql驅動

6、我們選擇的依賴內容
- 我們的專案會自動下載我們需要的這些框架組件的jar包,會幫我們默認配置好

7、專案的目錄結構

8、啟動后專案不報錯,就OK了!

轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/392100.html
標籤:java
