- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试配置我的项目。我有两种 tempalteResolver 变体。如果我使用这个:
@Bean
public SpringResourceTemplateResolver templateResolver() {
SpringResourceTemplateResolver templateResolver = new SpringResourceTemplateResolver();
templateResolver.setApplicationContext(applicationContext);
templateResolver.setPrefix("/WEB-INF/templates/");
templateResolver.setSuffix(".html");
templateResolver.setTemplateMode(TemplateMode.HTML);
templateResolver.setCacheable(true);
return templateResolver;
}
我得到一个错误,我的模板无法解析 thymeleaf 语法,即使我添加了 xmlns:th="http://www.thymeleaf.org"
当我使用以下代码时:
@Bean
public ClassLoaderTemplateResolver templateResolver() {
ClassLoaderTemplateResolver templateResolver = new ClassLoaderTemplateResolver();
templateResolver.setPrefix("/WEB-INF/templates/");
templateResolver.setSuffix(".html");
templateResolver.setTemplateMode(TemplateMode.HTML);
templateResolver.setCacheable(false);
templateResolver.setCharacterEncoding("UTF-8");
return templateResolver;
}
我收到一条错误消息,指出此路径 (/WEB-INF/templates) 下没有模板。
我的模板的完整路径是 src\main\webapp\WEB-INF\templates\
最好使用的模板解析器是什么?为什么?
谢谢!
最佳答案
You should be using SpringResourceTemplateResolver for web projects (using SpringMvc controllers), and ClassLoaderTemplateResolver for command line projects, or when you need to generate html for non-web applications (such as sending html email or something like that).
第一个错误发生是因为 spring security 以某种方式没有连接到项目和我的
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
modelAndView.addObject("auth", auth);
发送空值。第二个错误我不知道为什么会发生。
关于spring - SpringResourceTemplateResolver 和 ClassLoaderTemplateResolver 有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54789203/
我正在尝试配置我的项目。我有两种 tempalteResolver 变体。如果我使用这个: @Bean public SpringResourceTemplateResolver templ
我目前正在使用 Thymeleaf 设置 Spring MVC 项目,遵循以下教程:http://www.thymeleaf.org/doc/tutorials/3.0/thymeleafspring
我是一名优秀的程序员,十分优秀!