本文整理匯總了Java中freemarker.template.Configuration.setSetting方法的典型用法代碼示例。如果您正苦於以下問題:Java Configuration.setSetting方法的具體用法?Java Configuration.setSetting怎麽用?Java Configuration.setSetting使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類freemarker.template.Configuration
的用法示例。
在下文中一共展示了Configuration.setSetting方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: templateConfiguration
import freemarker.template.Configuration; //導入方法依賴的package包/類
private static Configuration templateConfiguration() {
Configuration configuration = new Configuration(Configuration.VERSION_2_3_26);
configuration.setDefaultEncoding("UTF-8");
configuration.setLogTemplateExceptions(false);
try {
configuration.setSetting("object_wrapper",
"DefaultObjectWrapper(2.3.26, forceLegacyNonListCollections=false, "
+ "iterableSupport=true, exposeFields=true)");
} catch (TemplateException e) {
e.printStackTrace();
}
configuration.setAPIBuiltinEnabled(true);
configuration.setClassLoaderForTemplateLoading(ClassLoader.getSystemClassLoader(),
"templates/ccda");
return configuration;
}
示例2: simpleCfg
import freemarker.template.Configuration; //導入方法依賴的package包/類
/**
* 創建默認配置的{@link Configuration}實例
* @return
*/
public static Configuration simpleCfg() throws TemplateException {
Configuration cfg = new Configuration(Configuration.VERSION_2_3_24);
cfg.setDefaultEncoding("UTF-8");
cfg.setSetting("locale", "zh_CN");
//cfg.setSetting("template_update_delay", "3600");
cfg.setSetting("classic_compatible", "true");
cfg.setSetting("number_format", "#.##");
cfg.setSetting("tag_syntax", "auto_detect");
cfg.setTemplateLoader(new ClassTemplateLoader(Freemarkers.class, "/"));
//因classic_compatible=true且對象的Date類型屬性為null時,表達式${obj.birth?datetime}會拋異常,所以自定義格式化
Map<String, TemplateDateFormatFactory> customDateFormats = new HashMap<>();
customDateFormats.put("date", JavaTemplateDateFormatFactory.INSTANCE);
cfg.setCustomDateFormats(customDateFormats);
cfg.setSetting("datetime_format", "@date yyyy-MM-dd HH:mm:ss");
cfg.setSetting("date_format", "@date yyyy-MM-dd");
cfg.setSetting("time_format", "@date HH:mm:ss");
return cfg;
}
示例3: FreemarkerTemplate
import freemarker.template.Configuration; //導入方法依賴的package包/類
public FreemarkerTemplate()
{
cfg = new Configuration();
try
{
//File cfgPath = new File(config.getConfigurationPath());
//cfg.setDirectoryForTemplateLoading( new File(cfgPath.getParent()) );
cfg.setServletContextForTemplateLoading(TernContext.getServletContext(),"/WEB-INF/views");
//cfg.setTemplateLoader(loader)
//cfg.setLocale(Locale.CHINA);
cfg.setSetting("date_format", "yyyy-MM-dd");
cfg.setSetting("time_format", "HH:mm:ss");
cfg.setSetting("datetime_format", "yyyy-MM-dd HH:mm:ss");
}
catch (Exception e)
{
cfg = null;
Trace.write(Trace.Error, e,"init freemarker failed!");
return;
}
cfg.setDefaultEncoding(config.getEncoding());
cfg.setOutputEncoding(config.getEncoding());
wrapper = new ActionDataWrapper();//ObjectWrapper.BEANS_WRAPPER;//.DEFAULT_WRAPPER;
/*wrapper = new DefaultObjectWrapper(){
public TemplateModel wrap(Object obj) throws TemplateModelException {
if(obj instanceof com.tern.dao.RecordSet){
return new freemarker.template.SimpleCollection(((com.tern.dao.RecordSet)obj).iterator(), this);
}
return super.wrap(obj);
}
};*/
cfg.setObjectWrapper(wrapper);
cfg.setTemplateExceptionHandler(new TemplateExceptionHandler(){
@Override
public void handleTemplateException(TemplateException te,
Environment env, Writer writer) throws TemplateException {
if(config.isDebug())
{
if(te.getCause() instanceof RedirectRequest)
{
throw (RedirectRequest)te.getCause();
}
TemplateExceptionHandler.HTML_DEBUG_HANDLER.handleTemplateException(te, env, writer);
}
throw te;
}
});
/*if(config.isDebug())
{
cfg.setTemplateExceptionHandler(TemplateExceptionHandler.HTML_DEBUG_HANDLER);
cfg.setTemplateUpdateDelay(0);
}
else
{
cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
cfg.setTemplateUpdateDelay(config.getInt("template.delay", 3600));
}*/
if(!config.isDebug())
{
cfg.setTemplateUpdateDelay(config.getInt("template.delay", 3600));
}
}