[TOC]html
public Result<String> hello() {
return Result.success("hello,imooc");
// return new Result(0, "success", "hello,imooc");
// 每次都要 new 對象,浪費
// 看起來也乾淨利落
}
複製代碼
return hello,SpringBoot 會自動尋找視圖解析器,好比我配置的 Thymeleaf,而後根據配置文件spring
#在構建 URL 時添加的前綴
spring.thymeleaf.prefix=classpath:/templates/
#構建 URL 時添加的後綴
spring.thymeleaf.suffix=.html
複製代碼
組裝成轉發路徑 hello.html緩存
@RequestMapping("/thymeleaf")
public String thymeleaf(Model model) {
model.addAttribute("name", "Xiehang");
return "hello";
}
複製代碼
thymeleaf 配置文件安全
#不緩存頁面
spring.thymeleaf.cache=false
#內容爲 text/html
spring.thymeleaf.content-type=text/html
#啓用 MVC thymeleaf 視圖解析
spring.thymeleaf.enabled=true
#模板編碼
spring.thymeleaf.encoding=UTF-8
#要應用於模板的模板模式
spring.thymeleaf.mode=HTML5
#在構建 URL 時添加的前綴
spring.thymeleaf.prefix=classpath:/templates/
#構建 URL 時添加的後綴
spring.thymeleaf.suffix=.html
複製代碼
Mybatis 配置bash
# mybatis
mybatis.type-aliases-package=com.xiehang.miaosha.domain
mybatis.configuration.map-underscore-to-camel-case=true
mybatis.configuration.default-fetch-size=100
mybatis.configuration.default-statement-timeout=3000
mybatis.mapperLocations = classpath:com/xiehang/miaosha/dao/*.xml
複製代碼
這裏不採用 xml 的方式配置 SQL 語句,而是在 dao 接口上寫註解 @select、@update...mybatis
@Mapper
public interface UserDao {
@Select("select * from user where id = #{id}")
public User getById(@Param("id") int id);
}
複製代碼