1、使用Spring Initialize向?qū)?chuàng)建項目





2、創(chuàng)建成功后springboot相關(guān)的在pom.xml中配置已經(jīng)注入成功了
3、創(chuàng)建HelloController.java文件

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
// 這個類的所有方法返回的數(shù)據(jù)直接寫給瀏覽器,如果是對象轉(zhuǎn)為json數(shù)據(jù)
//@Controller
//@ResponseBody
@RestController // 相當于 @Controller @ResponseBody
public class HelloController {
@RequestMapping("/hello")
public String hello(){
return "Hello World!";
}
}
4、resources下的目錄文件

- static:保存所有的靜態(tài)資源:js、css、images
- templates:保存所有的模板頁面;(SpringBoot默認jar包使用嵌入式的Tomcat,默認不支持JSP頁面);可以使用模板引擎(freemarker、thymeleaf)
- application.properties:SpringBoot應(yīng)用的配置文件;可以修改一些默認設(shè)置,比如修改端口號將默認的端口號8080修改為8081
