解决打包的时候,把模板一起打包了,修改模板文件还得重新打包。
自定义访问路径
@Configuration
public class WebMvcAutoConfiguration extends WebMvcConfigurationSupport {
// 配置文件自定义访问路径 也可以通过启动参数修改
@Value("${mole.work}")
private String work;
/***
* @apiNote 设置模板位置
* @author yepk
* @date 2022-08-05 上午 09:20
*/
@Bean
public FreeMarkerConfigurer freemarkerConfig() throws IOException, TemplateException {
FreeMarkerConfigurer configurer = new FreeMarkerConfigurer();
configurer.setTemplateLoaderPaths(work + "front/", "classpath:/front/");
configurer.setDefaultEncoding("UTF-8");
freemarker.template.Configuration configuration = configurer.createConfiguration();
configuration.setNewBuiltinClassResolver(TemplateClassResolver.SAFER_RESOLVER);
configuration.setTagSyntax(freemarker.template.Configuration.AUTO_DETECT_TAG_SYNTAX);
configurer.setConfiguration(configuration);
return configurer;
}
/***
* @apiNote 配置视图解析器
* @author yepk
* @date 2022-08-05 上午 09:20
*/
@Override
public void configureViewResolvers(ViewResolverRegistry registry) {
FreeMarkerViewResolver resolver = new FreeMarkerViewResolver();
resolver.setAllowRequestOverride(false);
resolver.setCache(false);
resolver.setExposeRequestAttributes(false);
resolver.setExposeSessionAttributes(false);
resolver.setExposeSpringMacroHelpers(true);
resolver.setSuffix(".ftl");
resolver.setContentType("text/html; charset=UTF-8");
registry.viewResolver(resolver);
}
}