在用springboot整合freemarker的标签输出数字的时候,超过3位数字就会自动加上逗号,需要去除逗号,试了settings.setProperty("number_format", "#")发现并不能解决,方法如下:
@Configuration
public class FreeMarkerConfig {
@Bean
public FreeMarkerConfigurer freeMarkerConfigurer() throws IOException, TemplateException {
FreeMarkerConfigurer freeMarkerConfigurer = new FreeMarkerConfigurer();
FreeMarkerConfigurationFactory factory = new FreeMarkerConfigurationFactory();
factory.setTemplateLoaderPath("");
factory.setDefaultEncoding("UTF-8");
factory.setPreferFileSystemAccess(false);
freemarker.template.Configuration configuration = factory.createConfiguration();
configuration.setClassicCompatible(true);
freeMarkerConfigurer.setConfiguration(configuration);
//数字格式去除逗号
Properties settings = new Properties();
settings.setProperty("number_format", "#");
freeMarkerConfigurer.setFreemarkerSettings(settings);
return freeMarkerConfigurer;
}
}
经过多次配置测试后发现使用configuration.setNumberFormat("#")可以解决问题,方法如下:
@Bean
public FreeMarkerConfigurer freeMarkerConfigurer() throws IOException, TemplateException {
FreeMarkerConfigurer freeMarkerConfigurer = new FreeMarkerConfigurer();
FreeMarkerConfigurationFactory factory = new FreeMarkerConfigurationFactory();
factory.setTemplateLoaderPath("classpath:/templates/"+theme+"/");
factory.setDefaultEncoding("UTF-8");
factory.setPreferFileSystemAccess(false);
freemarker.template.Configuration configuration = factory.createConfiguration();
configuration.setClassicCompatible(true);
//数字格式去除逗号
configuration.setNumberFormat("#");
freeMarkerConfigurer.setConfiguration(configuration);
return freeMarkerConfigurer;
}