SpringBoot_Themeleaf

http://www.thymeleaf.org/doc/tutorials/2.1/usingthymeleaf.html
http://blog.csdn.net/u012706811/article/details/52185345
springboot有很多默认配置
默认页面映射路径:classpath:/templates/*.html
静态文件路径为 classpath:/static/

springboot默认使用themeleaf模板引擎
pom.xml添加依赖

   
            org.springframework.boot 
            spring-boot-starter-thymeleaf  
  

在application.properties中配置themeleaf模板解析器属性

spring.thymeleaf.mode=HTML5
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.content-type=text/html
#开发时关闭缓存,不然没法看到实时页面
# Allow Thymeleaf templates to be reloaded at dev time    
spring.thymeleaf.cache=false    

注意:在spring-boot下,默认约定了Controller试图跳转中thymeleaf模板文件的前缀prefix是”classpath:/templates/”,后缀suffix是”.html”

添加themeleaf命名空间


页面demo




    hello
    



Controller层

@Controller
@RequestMapping("/themeleaf")
public class HelloThemeController{
    @RequestMapping(value="/hello",method = RequestMethod.GET)
    public String helloTheme(Model model){
        model.addAttribute("name", "world");
        return "/hello";
    }
}

你可能感兴趣的:(SpringBoot_Themeleaf)