SpringBoot beetl 自定义静态文件的位置

解决打包的时候,把模板一起打包了,修改模板文件还得重新打包。

自定义访问路径

@Configuration
public class WebMvcAutoConfiguration extends WebMvcConfigurationSupport {

    // 配置文件自定义访问路径 也可以通过启动参数修改
    @Value("${mole.work}")
    private String work;
    // 运行环境判断
    @Value("${spring.profiles.active}")
    private String profiles;  
    
    
    @Bean
    public BeetlTemplateCustomize beetlTemplateCustomize() {
        return groupTemplate -> {
            // 测试环境
            if ("dev".equals(profiles)) {
                ClassLoader loader = Thread.currentThread().getContextClassLoader();
                ClasspathResourceLoader cploder = new ClasspathResourceLoader(loader, "admin");
                groupTemplate.setResourceLoader(cploder);
            } else {
                FileResourceLoader resourceLoader = new FileResourceLoader(workDir + "admin/", "utf-8");
                groupTemplate.setResourceLoader(resourceLoader);
            }
        };
    }

    @Bean(name = "beetlViewResolver")
    public BeetlSpringViewResolver getBeetlSpringViewResolver(BeetlGroupUtilConfiguration beetlGroupUtilConfiguration) {
        BeetlSpringViewResolver beetlSpringViewResolver = new BeetlSpringViewResolver();
        beetlSpringViewResolver.setContentType("text/html;charset=UTF-8");
        beetlSpringViewResolver.setOrder(0);
        beetlSpringViewResolver.setSuffix(".html");
        beetlSpringViewResolver.setOrder(0);
        beetlSpringViewResolver.setConfig(beetlGroupUtilConfiguration);
        return beetlSpringViewResolver;
    }
    
}

如果修改外部模板后要重新加载模板使之生效。

# springboot   beetl  

评论

企鹅群:39438021

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×