zoukankan      html  css  js  c++  java
  • SpringBoot Thymeleaf 配置多个Template Locations

    @Configuration
    public class ThymeleafConfigration {
    
        @Bean
        public SpringResourceTemplateResolver firstTemplateResolver() {
            SpringResourceTemplateResolver templateResolver = new SpringResourceTemplateResolver();
            //templateResolver.setPrefix("classpath:/templates2/");
    
            File path = null;
            try {
                path = new File(ResourceUtils.getURL("classpath:").getPath());
                //file:/data/github/testmanagement/target/testmanagement-0.0.1-SNAPSHOT.jar!/BOOT-INF/classes!
                System.out.println(path.getPath());
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
            //server.tomcat.basedir=outsidefile/jacococoverage
            String outside_templates=path.getParentFile().getParentFile().getParent()+File.separator;
            //String outside_templates=path.getParentFile().getParentFile().getParent()+File.separator+"outsidefile"+File.separator+"jacococoverage"+File.separator;
    
            System.out.println(outside_templates);
            outside_templates=outside_templates.substring(5,outside_templates.length());
            //file:/data/github/testmanagement/target/outsidefile/jacococoverage/
    
            System.out.println("new outside_templates is "+outside_templates);
            templateResolver.setPrefix("file://"+outside_templates);
    
            templateResolver.setSuffix(".html");
            templateResolver.setTemplateMode(TemplateMode.HTML);
            templateResolver.setCharacterEncoding("UTF-8");
    //        templateResolver.setOrder(0);
            templateResolver.setCheckExistence(true);
    
            //Spring Boot中Thymeleaf引擎动态刷新
            templateResolver.setCacheable(false);
            return templateResolver;
        }
    
    //    @Bean
    //    public ClassLoaderTemplateResolver secondaryTemplateResolver() {
    //        ClassLoaderTemplateResolver secondaryTemplateResolver = new ClassLoaderTemplateResolver();
    //        secondaryTemplateResolver.setPrefix("templates-2/");
    //        secondaryTemplateResolver.setSuffix(".html");
    //        secondaryTemplateResolver.setTemplateMode(TemplateMode.HTML);
    //        secondaryTemplateResolver.setCharacterEncoding("UTF-8");
    //        secondaryTemplateResolver.setOrder(1);
    //        secondaryTemplateResolver.setCheckExistence(true);
    //
    //        return secondaryTemplateResolver;
    //    }
    }
    
  • 相关阅读:
    [译]Node.js Interview Questions and Answers (2017 Edition)
    XUnit
    Inline Route Constraints in ASP.NET Core MVC
    [译]Object.getPrototypeOf
    [译]IIS 8.0应用初始化
    C++的那些事:你真的了解引用吗
    C++的那些事:表达式与语句
    C++的那些事:数据与类型
    神经网络:卷积神经网络
    图像分析:投影曲线的波峰查找
  • 原文地址:https://www.cnblogs.com/xidianzxm/p/11590345.html
Copyright © 2011-2022 走看看