简体   繁体   English

Spring Boot-Thymeleaf模板

[英]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.

相关问题 Spring Boot-Thymeleaf模板-多个解析器 - Spring boot - Thymeleaf template - multiple resolvers Thymeleaf 3 Beta的春季靴子 - Spring boot with Thymeleaf 3 Beta 使用Thymeleaf和AngularJS ui路由器的Spring Boot - Spring Boot with Thymeleaf and AngularJS ui-router Spring Boot Thymeleaf和angularjs 1-Angularjs HTTP请求到Spring Controller不绑定在百里香视图中 - Spring boot Thymeleaf and angularjs 1 - angularjs http request to spring controller not binding in thymeleaf view 如何在春季靴子Thymeleaf中使用角度双向绑定标签 - How to use angular two way binding tag in spring boot Thymeleaf 在Spring启动MVC中使用模板引擎 - Use of template engines in Spring boot MVC AngularJS通过调用Spring Boot Controller来响应thymeleaf.exceptions.TemplateInputException - AngularJS via calling to Spring boot Controller responded with thymeleaf.exceptions.TemplateInputException AngularJS - 错误:[$compile:tpload] 无法加载模板(Spring Boot) - AngularJS - Error: [$compile:tpload] Failed to load template (Spring Boot) Spring Boot模板可能不存在,或者任何配置的模板解析器都无法访问 - Spring boot template might not exist or might not be accessible by any of the configured Template Resolvers Thymeleaf + Boot + AngularJS指令解析器错误 - Thymeleaf + Boot + AngularJS directives parser error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM