file-new -Spring Stater project web依賴
@RestController
@SpringBootApplication
public class HelloSpringBootApplication {
@RequestMapping("/")
public String hello(){
return "hello SpringBoot";
}
public static void main(String[] args) {
SpringApplication.run(HelloSpringBootApplication.class, args);
}
}
localhost:8080/ 10行實現SpringMVC 不需要配置任何XML文件。
file-new-spring stater project web Thymeleaf依賴
@Controller
@SpringBootApplication
public class HelloSpringBootApplication {
@RequestMapping("/")
public String hello(){
return "index";
}
public static void main(String[] args) {
SpringApplication.run(HelloSpringBootApplication.class, args);
}
}
定向到index.htmlindex.html 放到resource/templates裏
<html>
<head>
<meta charset="UTF-8"></meta>
<title>Insert title here</title>
</head>
<body>
HEllo SpringBoot
</body>
</html>
localhost:8080/
上面2個程序主要的不同是 @RestController和@Controller
@RestController 是@Controller和ResponseBody的結合體 說明return的是response
PS:
SpringBootApplication 開啓自動配置
SpringApplication.run(Main.class,args) Spring boot 入口
application.properties 配置
tomcat:
server.port=***
Profile 不同環境對不同配置提供支持
不同的配置文件 application-{profile}.properties
在application.properties裏配置
spring.profiles.active= profile