生成項目
可以通過Spring官方網(wǎng)站進行生成牲距。
https://start.spring.io
Controller注解
給方法添加注解
@RequestMapping(value={"/index","/show"},method= RequestMethod.GET)
@ResponseBody
如果一個Controller中有很多個方法神帅,每個方法都需要使用@ResponseBody注解螃概,此時可以將類注解@Controller換成@RestController前普。一旦換成@RestController,則方法不再需要注解@ResponseBody。
同時RequestMapping可以換成GetMapping和PostMapping
Spring Boot配置
Spring Boot的內(nèi)置容器Tomcat/jetty/undertow
修改端口號:application.properties中添加server.port=8081
修改項目路徑: server.servlet.context-path=xxxxxxx(2.0版本以后)
修改Spring Boot啟動時的橫幅
添加banner.txt
或者使用xxx.txt
并進行如下配置:spring.banner.location=classpath:xxx.txt