Themyleaf

依赖

  
    org.thymeleaf  
    thymeleaf-spring4  
    3.0.0.RELEASE  
  

gradle依赖如下

compile group: 'org.thymeleaf', name: 'thymeleaf-spring4', version: '3.0.2.RELEASE'

Thymeleaf3 之前:

@Bean  
public TemplateResolver templateResolver() {  
  TemplateResolver resolver = new ServletContextTemplateResolver();  
  resolver.setPrefix("/WEB-INF/VIEWS/");  
  resolver.setSuffix(".html");  
  resolver.setTemplateMode("HTML5");  
  resolver.setCacheable(false);  
  return resolver;  
}  

Thymeleaf3 现在:

public ITemplateResolver templateResolver() {  
    SpringResourceTemplateResolver resolver = new SpringResourceTemplateResolver();  
    resolver.setPrefix("/WEB-INF/VIEWS/");  
    resolver.setSuffix(".html");  
    resolver.setTemplateMode(TemplateMode.HTML);  
    resolver.setCacheable(false);  
    return resolver;  
}  

javaConfig:

@Configuration  
@EnableWebMvc  
@ComponentScan(value="com.qiqi.test.web")  
public class WebConfig extends WebMvcConfigurerAdapter{  
    @Bean  
    public ITemplateResolver  templateResolver() {  
         SpringResourceTemplateResolver templateResolver = new SpringResourceTemplateResolver();  
        templateResolver.setTemplateMode("HTML5");  
        templateResolver.setPrefix("/WEB-INF/VIEWS/");  
        templateResolver.setSuffix(".html");  
        templateResolver.setCharacterEncoding("utf-8");  
        templateResolver.setOrder(1);  
  
        templateResolver.setCacheable(false);  
        return templateResolver;  
    }  
  
    @Bean  
    public SpringTemplateEngine templateEngine() {  
           SpringTemplateEngine templateEngine = new SpringTemplateEngine();  
            templateEngine.setTemplateResolver(templateResolver());  
            return templateEngine;  
    }  
  
  
    @Bean  
//    public ViewResolver  viewResolver() {  
    public ThymeleafViewResolver  viewResolver() {    
        ThymeleafViewResolver viewResolver = new ThymeleafViewResolver();  
        viewResolver.setTemplateEngine(templateEngine());  
        viewResolver.setCharacterEncoding("utf-8");  
        return viewResolver;  
    }  

你可能感兴趣的:(Themyleaf)