[英]Spring Boot - Thymeleaf template
I am using Spring Boot 1.2.7 and Thymeleaf. 我正在使用Spring Boot 1.2.7和Thymeleaf。
All the html pages are inside the src/main/resource/templates
folder and everything works fine when I say return "<viewName>"
inside the controller. 所有的html页面都在
src/main/resource/templates
文件夹内,当我说在控制器内return "<viewName>"
时,一切工作正常。
Now, I would like to use different folder structure for AngularJS. 现在,我想对AngularJS使用不同的文件夹结构。
Would like to move the pages to some other folder, say webapps/pages
. 想要将页面移动到其他文件夹,例如
webapps/pages
。
Tried configuring the resolver as below, 尝试按以下方式配置解析器,
@Configuration
public class MvcConfig extends WebMvcConfigurerAdapter {
@Bean
public ServletContextTemplateResolver getViewResolver() {
ServletContextTemplateResolver resolver = new ServletContextTemplateResolver();
resolver.setPrefix("webapps/pages/");
resolver.setSuffix(".html");
resolver.setTemplateMode("LEGACYHTML5");
return resolver;
}
@Override
public void configureDefaultServletHandling(
DefaultServletHandlerConfigurer configurer) {
configurer.enable();
}
}
Still not working... Am I missing any other config or should I not use Thymeleaf in this case? 仍然无法正常工作...我是否缺少任何其他配置,或者在这种情况下不应该使用Thymeleaf?
pom.xml for your reference, pom.xml供您参考,
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
</dependencies>
You can configure one TemplateResolver
inside the application.properties
(or application.yml
) file, if you do not want to use the standard configuration. 如果不想使用标准配置,则可以在
application.properties
(或application.yml
)文件中配置一个TemplateResolver
。 You can find a list of available options in the docs . 您可以在docs中找到可用选项的列表。
Then introduce a new @Configuration
for additional TemplateResolver
s: 然后为其他
TemplateResolver
引入一个新的@Configuration
:
@Configuration
public class ThymeleafConfig {
@Autowired
private SpringTemplateEngine templateEngine;
@PostConstruct
public void init() {
ClassLoaderTemplateResolver resolver = new ClassLoaderTemplateResolver();
resolver.setPrefix("webapps/pages/");
resolver.setSuffix(".html");
resolver.setTemplateMode("LEGACYHTML5");
resolver.setOrder(templateEngine.getTemplateResolvers().size());
templateEngine.addTemplateResolver(resolver);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.