目前java的開發很多Learner都慢慢的學習使用IDEA這款工具,個人覺得其實相比Eclipse來說差不多,個人習慣的問題,但是我還是推薦IDEA這款工具。雖然它目前是收費的,但相信網上的各種破解方式很多,由於對學生和教師是可以免費使用的,所以個人推薦拿個學生郵箱去註冊一個,非常的方便快捷就是一個驗證而已,具體步驟就希望大家去網上get一下了。
好現在!我們通過IDEA來搭建一個簡單的web
勾選下面三個頁面的選項
等待,可能在Maven下載相關jar的時候時間會久一點
配置連接數據庫參數application.properties
spring.datasource.url = jdbc:mysql://localhost:3306/test
spring.datasource.username = root
spring.datasource.password = root
spring.datasource.driverClassName = com.mysql.jdbc.Driver
#頁面熱加載
spring.thymeleaf.cache = false
#端口
server.port=8080
這樣一個Web項目即完成,該頁面展示出來的項目名和我創建步驟中名稱不一樣,但創建步驟是一樣的只是命名不一樣而已。下面我們來測試一下
創建一個控制類
package com.lzc.springbootdemo;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class testController {
@RequestMapping("/index")
public ResponseEntity<String> index(){
String as = "hello";
return new ResponseEntity<String>(as, HttpStatus.OK);
}
}
運行程式
Run程式後在瀏覽器輸入http://localhost:8080/index
下面我們去轉發一個頁面
創建一個html頁面
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Title</title>
</head>
<body>
<h1>Hello World</h1>
</body>
</html>
下面修改控制類
package com.lzc.springbootdemo;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class testController {
// @RequestMapping("/index")
// public ResponseEntity<String> index(){
// String as = "hello";
//
// return new ResponseEntity<String>(as, HttpStatus.OK);
// return "test";
// }
@RequestMapping("/index")
public String index(){
return "test";
}
}
Run程式瀏覽器輸入 http://localhost:8080/index
就此項目測試完成,希望對大家有幫助。想想也很長時間沒有來寫博客了,有點混。