[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);
}
复制代码