<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
<artifactId>spring-boot-starter-web</artifactId>查看依賴時會發現其中包含了 Spring MVC 框架、SLF4J、Jackson和 Tomcat 等依賴。這實際上 Spring 推薦的 Web 應用中使用的開源庫的組合
@RestController啓動*Application.java 即可啓動默認的內嵌容器
@RequestMapping("test")
public class TestController {
/**
* 不區分get post
* localhost/test
* @author [email protected]
* @return
*/
@RequestMapping("")
String test() {
return "hello world";
}
}
/**
* 返回Map的json
*
* @return
*/
@RequestMapping("testMap")
Map<String, Object> testMap() {
Map<String, Object> map = new HashMap<>();
map.put("name", "jerome");
map.put("age", 26);
return map;
}
/**
* 返回List的json
*
* @return
*/
@RequestMapping("testList")
List<String> testList() {
List<String> list = new ArrayList<>();
list.add("蘇志達");
list.add("jerome");
return list;
}
/**
* 返回實體的json
*
* @return
*/
@RequestMapping("testModel")
User testModel() {
User user = new User("蘇志達", 26, 0, new Date(), 99.6);
return user;
}
#時間格式化
spring.jackson.date-format=yyyy-MM-dd HH:mm:ss
#時區設置
spring.jackson.time-zone=Asia/Chongqing
訪問資源
參考