我正在使用 Thymeleaf 构建一个 Web Spring Boot。当我刷新或更改页面时,我看到 Thymeleaf 总是加载所有资源,如 this Thymeleaf . 我如何从内存中缓存资源,类似于 .Net MVC 框架,它可以像 this 那样做 DotNetMVC
最佳答案
有两种方法可以做到这一点。
使用 WebMVCConfig。
使用 application.properties 文件
WebMVCConfig.
像这样创建模板解析器。
@Bean
public TemplateResolver templateResolver()
{
FileTemplateResolver templateResolver = new FileTemplateResolver();
templateResolver.setTemplateMode( "HTML5" );
templateResolver.setCacheable( Boolean.FALSE );
templateResolver.setOrder( 1 );
return templateResolver;
}
应用程序属性
将以下行添加到 application.properties 文件
spring.thymeleaf.cache: false
关于javascript - 缓存 CSS、JavaScript、Image Spring Boot (+Thymeleaf),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50923379/