搭建一個SpringBoot項目
-
建立檔案
打開IDEA -> New -> New Project -> Spring Initializr 使用預設 點選next
【學習日記】(SpringBoot-part 1)初學springboot—建立springboot項目 選擇依賴,根據你的項目需要進行勾選,我根據自己項目需要選擇了如下【學習日記】(SpringBoot-part 1)初學springboot—建立springboot項目 選擇好之後點選next-> finish【學習日記】(SpringBoot-part 1)初學springboot—建立springboot項目 【學習日記】(SpringBoot-part 1)初學springboot—建立springboot項目 - 配置Maven
【學習日記】(SpringBoot-part 1)初學springboot—建立springboot項目 -
配置資料庫(本次隻是建立一個sspringboot項目,暫時用不到資料庫,但是還是需要在配置檔案中配置好)
首先建立一個資料庫,名字為spring,目前沒建立新表。
修改配置檔案,根據自己學習來,我是将properties檔案改成yml檔案(直接重命名改字尾),再用yml進行配置資料庫相關資訊
在pom.xml檔案下修改資料庫連接配接版本和自己目前資料庫版本一緻【學習日記】(SpringBoot-part 1)初學springboot—建立springboot項目 【學習日記】(SpringBoot-part 1)初學springboot—建立springboot項目 - 檔案建立目錄如圖:
【學習日記】(SpringBoot-part 1)初學springboot—建立springboot項目 first.html用來檢視效果,建立一個控制器用來跳轉到first界面
first.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>标題</title>
</head>
<body>
myFirstSpringBoot
</body>
</html>
index.controller
@Controller
public class indexController {
//跳轉頁面
// @GetMapping("/") //等價于下面一行
@RequestMapping(method = RequestMethod.GET,value = "/")
public String index(){
return "first";
}
}
- 運作效果 打開8080端口檢視
【學習日記】(SpringBoot-part 1)初學springboot—建立springboot項目 運作成功【學習日記】(SpringBoot-part 1)初學springboot—建立springboot項目