本文整理匯總了Java中freemarker.template.Configuration.setNumberFormat方法的典型用法代碼示例。如果您正苦於以下問題:Java Configuration.setNumberFormat方法的具體用法?Java Configuration.setNumberFormat怎麽用?Java Configuration.setNumberFormat使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類freemarker.template.Configuration
的用法示例。
在下文中一共展示了Configuration.setNumberFormat方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: buildFreemarkerHelper
import freemarker.template.Configuration; //導入方法依賴的package包/類
private FreemarkerHelper buildFreemarkerHelper(File templateBaseDir) {
Configuration configuration = new Configuration(new Version(2, 3, 0));
try {
TemplateLoader templateLoader = new FileTemplateLoader(templateBaseDir);
configuration.setTemplateLoader(templateLoader);
} catch (IOException e) {
throw new GeneratorException("構建模板助手出錯:" + e.getMessage());
}
configuration.setNumberFormat("###############");
configuration.setBooleanFormat("true,false");
configuration.setDefaultEncoding("UTF-8");
// 自動導入公共文件,用於支持靈活變量
if (autoIncludeFile.exists()) {
List<String> autoIncludeList = new ArrayList<>();
autoIncludeList.add(FREEMARKER_AUTO_INCLUDE_SUFFIX);
configuration.setAutoIncludes(autoIncludeList);
}
return new FreemarkerHelper(configuration);
}
示例2: prepareConfiguration
import freemarker.template.Configuration; //導入方法依賴的package包/類
private static Configuration prepareConfiguration() {
Configuration result = new Configuration(Configuration.VERSION_2_3_26);
result.setNumberFormat("computer");
result.setDefaultEncoding(StandardCharsets.UTF_8.name());
result.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
result.setLogTemplateExceptions(false);
return result;
}
示例3: afterPropertiesSet
import freemarker.template.Configuration; //導入方法依賴的package包/類
@Override
public void afterPropertiesSet() throws IOException, TemplateException {
super.afterPropertiesSet();
Configuration cfg = this.getConfiguration();
cfg.setSharedVariable("shiro", new ShiroTags());// shiro標簽
cfg.setNumberFormat("#");// 防止頁麵輸出數字,變成2,000
// 可以添加很多自己的要傳輸到頁麵的[方法、對象、值]
}
示例4: main
import freemarker.template.Configuration; //導入方法依賴的package包/類
public static void main(String[] args) {
Configuration config = new Configuration();
try {
config.setClassForTemplateLoading(HelloFreeMarker.class, "");
// 去掉int型輸出時的逗號, 例如: 123,456
// config.setNumberFormat("#"); // config.setNumberFormat("0"); 也可以
config.setNumberFormat("#0.#####");
config.setDateFormat("yyyy-MM-dd");
config.setTimeFormat("HH:mm:ss");
config.setDateTimeFormat("yyyy-MM-dd HH:mm:ss");
config.setDateTimeFormat("yyyy-MM-dd HH");
config.setSharedVariable("sharedChen", "sharedChen");
config.setSharedVariable("name", "HelloFreeMarker----------------SharedVariable");
Template myTemplate = config.getTemplate("hellofreemarker.ftl");
Map<String,Object> dataModel = new HashMap<String, Object>();
dataModel.put("name", "HelloFreeMarker");
dataModel.put("date1", (new Date()).toString());
dataModel.put("dateO", new Date());
dataModel.put("staticUser", User.class);
dataModel.put("chen","");
User user = User.getUser();
dataModel.put("user",user);
List temp = new ArrayList();
temp.add("1");
temp.add("2");
temp.add("322");
dataModel.put("list", temp);
StringWriter sw = new StringWriter();
myTemplate.process(dataModel, sw);
System.out.println(sw.toString());
} catch (Exception e) {
e.printStackTrace();
}
}