springboot自學小結
Spring Boot的優缺點
快速入門:
1.設定springboot的parent
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.2.RELEASE</version>
</parent>
說明:Spring boot的專案必須要將parent設定為spring boot的parent,該parent包含了大量預設的配置,大大簡化了我們的開發。
2.匯入spring boot的web支援
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
3.新增Spring boot的外掛
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-
</plugin>
4.編寫第一個Spring Boot的應用
@Controller
@SpringBootApplication
@Configuration
public class HelloApplication {
@RequestMapping("hello")
@ResponseBody
public String hello(){
return "hello world!";
}
public static void main(String[]
SpringApplication.run(HelloApplication.class, args);
}
}
程式碼說明:
1、@SpringBootApplication:Spring Boot專案的核心註解,主要目的是開啟自動配置。;
2、@Configuration:這是一個配置Spring的配置類;
3、@Controller:標明這是一個SpringMVC的Controller控制器;
4、main方法:在main方法中啟動一個應用,即:這個應用的入口;