當前位置: 首頁>>代碼示例>>Java>>正文


Java FreeMarkerConfigurer類代碼示例

本文整理匯總了Java中org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer的典型用法代碼示例。如果您正苦於以下問題:Java FreeMarkerConfigurer類的具體用法?Java FreeMarkerConfigurer怎麽用?Java FreeMarkerConfigurer使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


FreeMarkerConfigurer類屬於org.springframework.web.servlet.view.freemarker包,在下文中一共展示了FreeMarkerConfigurer類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: freemarkerConfig

import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer; //導入依賴的package包/類
@Bean
public FreeMarkerConfigurer freemarkerConfig() throws IOException, TemplateException {
	final FreeMarkerConfigurationFactory factory = new FreeMarkerConfigurationFactory();

	// If overwritten use path of user
	if (isNotBlank(uaaProperties.getTemplatePath())) {
		final TemplateLoader templateLoader = getTemplateLoader(uaaProperties.getTemplatePath());
		factory.setPreTemplateLoaders(templateLoader);
	}

	// Default configurations
	factory.setPostTemplateLoaders(getTemplateLoader("classpath:/templates/"));
	factory.setDefaultEncoding("UTF-8");

	final FreeMarkerConfigurer result = new FreeMarkerConfigurer();
	result.setConfiguration(factory.createConfiguration());
	return result;
}
 
開發者ID:JanLoebel,項目名稱:uaa-service,代碼行數:19,代碼來源:TemplateConfig.java

示例2: freeMarkerConfigurer

import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer; //導入依賴的package包/類
@Bean
	@ConditionalOnMissingBean({FreeMarkerConfig.class, FreeMarkerViewResolver.class})
	public FreeMarkerConfigurer freeMarkerConfigurer() {
		PluginFreeMarkerConfigurer configurer = new PluginFreeMarkerConfigurer();
		applyProperties(configurer);
		String[] paths = this.properties.getTemplateLoaderPath();
//		paths = ArrayUtils.add(paths, WEBFTLS_PATH);
		configurer.setTemplateLoaderPaths(paths);
		
		List<WithAnnotationBeanData<FreeMarkerViewTools>> tools = SpringUtils.getBeansWithAnnotation(applicationContext, FreeMarkerViewTools.class);
		tools.forEach(t->{
			String name = t.getAnnotation().value();
			if(StringUtils.isBlank(name)){
				name = t.getBean().getClass().getSimpleName();
			}
			configurer.setFreemarkerVariable(name, t.getBean());
			logger.info("registered FreeMarkerViewTools : {}", name);
		});
		return configurer;
	}
 
開發者ID:wayshall,項目名稱:onetwo,代碼行數:21,代碼來源:WebFtlsContextConfig.java

示例3: EmailServiceImpl

import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer; //導入依賴的package包/類
public EmailServiceImpl(FreeMarkerConfigurer freemarkerConfig, MessageSource messageSource, JavaMailSender javaMailSender, 
                    String baseURL, String defaultReplyTo, String sendToOM, String sendToVRK, 
                    int invitationExpirationDays, String testSendTo, boolean testConsoleOutput) {
    this.freemarkerConfig = freemarkerConfig;
    this.messageSource = messageSource;
    this.javaMailSender = javaMailSender;
    this.baseURL = baseURL;
    this.defaultReplyTo = defaultReplyTo;
    this.invitationExpirationDays = invitationExpirationDays;
    this.sendToOM = sendToOM;
    this.sendToVRK = sendToVRK;
    
    if (Strings.isNullOrEmpty(testSendTo)) {
        this.testSendTo = null;
    } else {
        this.testSendTo = testSendTo;
    }
    this.testConsoleOutput = testConsoleOutput;
}
 
開發者ID:solita,項目名稱:kansalaisaloite,代碼行數:20,代碼來源:EmailServiceImpl.java

示例4: getFreemarkerConfig

import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer; //導入依賴的package包/類
@Bean
public FreeMarkerConfigurer getFreemarkerConfig() throws IOException, TemplateException {
	final FreeMarkerConfigurationFactory factory = new FreeMarkerConfigurationFactory();
	factory.setTemplateLoaderPath("/WEB-INF/views/");
	factory.setDefaultEncoding("UTF-8");
	final Properties properties = new Properties();
	properties.put("auto_import", "spring.ftl as spring");
	properties.put("template_exception_handler", "rethrow");
	factory.setFreemarkerSettings(properties);
	final Map<String, Object> sharedVariables = new HashMap<String, Object>();
	sharedVariables.put("include", this.freemarkerIncludeDirective);
	factory.setFreemarkerVariables(sharedVariables);
	factory.setPreferFileSystemAccess(false);

	final FreeMarkerConfigurer result = new FreeMarkerConfigurer();
	// FIXME factory not working
	// result.setConfiguration(factory.createConfiguration());
	result.setTemplateLoaderPath("/WEB-INF/views/");
	result.setFreemarkerVariables(sharedVariables);
	result.setFreemarkerSettings(properties);

	return result;
}
 
開發者ID:TeeFun,項目名稱:TeeFun,代碼行數:24,代碼來源:MvcConfig.java

示例5: freemarkerConfig

import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer; //導入依賴的package包/類
/**
 * FreeMarker (ftl) configuration
 */
@Bean
public FreeMarkerConfigurer freemarkerConfig() throws IOException, TemplateException {
	final FreeMarkerConfigurer result = new FreeMarkerConfigurer();

	// template path
	result.setTemplateLoaderPath("/WEB-INF/ftl/");
	result.setDefaultEncoding("UTF-8");

	// static access
	final Version version = freemarker.template.Configuration.getVersion();
	final BeansWrapper wrapper = new BeansWrapper(version);
	final TemplateHashModel statics = wrapper.getStaticModels();
	final Map<String, Object> shared = new HashMap<>();
	for (final Class<?> clazz : ElFunctions.staticClasses) {
		shared.put(clazz.getSimpleName(), statics.get(clazz.getName()));
	}
	result.setFreemarkerVariables(shared);

	return result;
}
 
開發者ID:Katharsas,項目名稱:GMM,代碼行數:24,代碼來源:ApplicationConfiguration.java

示例6: configureFreemarker

import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer; //導入依賴的package包/類
@Bean
public FreeMarkerConfigurer configureFreemarker() {
    FreeMarkerConfigurer freeMarkerConfigurer = new FreeMarkerConfigurer();
    Properties settings = new Properties();

    settings.setProperty(freemarker.template.Configuration.TEMPLATE_EXCEPTION_HANDLER_KEY, "rethrow");
    freeMarkerConfigurer.setFreemarkerSettings(settings);
    freeMarkerConfigurer.setTemplateLoaderPath(FreeMarkerProperties.DEFAULT_TEMPLATE_LOADER_PATH);

    return freeMarkerConfigurer;
}
 
開發者ID:scionaltera,項目名稱:emergentmud,代碼行數:12,代碼來源:HttpConfiguration.java

示例7: freemarkerConfigurer

import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer; //導入依賴的package包/類
@Bean
public FreeMarkerConfigurer freemarkerConfigurer() throws IOException {
    FreeMarkerConfigurer result = new FreeMarkerConfigurer();
    if (nixmashModeEnabled)
        result.setTemplateLoaderPath("classpath:/nixmarker/");
    else
        result.setTemplateLoaderPath("classpath:/freemarker/");
    return result;
}
 
開發者ID:mintster,項目名稱:nixmash-blog,代碼行數:10,代碼來源:MailConfig.java

示例8: freeMarker

import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer; //導入依賴的package包/類
/**
 * Register a FreeMarker view resolver with an empty default view name
 * prefix and a default suffix of ".ftl".
 *
 * <p><strong>Note</strong> that you must also configure FreeMarker by adding a
 * {@link org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer} bean.
 */
public UrlBasedViewResolverRegistration freeMarker() {
	if (this.applicationContext != null && !hasBeanOfType(FreeMarkerConfigurer.class)) {
		throw new BeanInitializationException("In addition to a FreeMarker view resolver " +
				"there must also be a single FreeMarkerConfig bean in this web application context " +
				"(or its parent): FreeMarkerConfigurer is the usual implementation. " +
				"This bean may be given any name.");
	}
	FreeMarkerRegistration registration = new FreeMarkerRegistration();
	this.viewResolvers.add(registration.getViewResolver());
	return registration;
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:19,代碼來源:ViewResolverRegistry.java

示例9: setUp

import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer; //導入依賴的package包/類
@Before
public void setUp() {
	StaticWebApplicationContext context = new StaticWebApplicationContext();
	context.registerSingleton("freeMarkerConfigurer", FreeMarkerConfigurer.class);
	context.registerSingleton("velocityConfigurer", VelocityConfigurer.class);
	context.registerSingleton("tilesConfigurer", TilesConfigurer.class);
	context.registerSingleton("groovyMarkupConfigurer", GroovyMarkupConfigurer.class);
	context.registerSingleton("scriptTemplateConfigurer", ScriptTemplateConfigurer.class);
	this.registry = new ViewResolverRegistry();
	this.registry.setApplicationContext(context);
	this.registry.setContentNegotiationManager(new ContentNegotiationManager());
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:13,代碼來源:ViewResolverRegistryTests.java

示例10: process

import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer; //導入依賴的package包/類
/**
 * 解析字符串模板
 * 
 * @param template
 *            字符串模板
 * @param model
 *            數據
 * @return 解析後內容
 */
public static String process(String template, Map<String, ?> model) throws IOException, TemplateException {
	Configuration configuration = null;
	ApplicationContext applicationContext = SpringUtils.getApplicationContext();
	if (applicationContext != null) {
		FreeMarkerConfigurer freeMarkerConfigurer = SpringUtils.getBean("freeMarkerConfigurer", FreeMarkerConfigurer.class);
		if (freeMarkerConfigurer != null) {
			configuration = freeMarkerConfigurer.getConfiguration();
		}
	}
	return process(template, model, configuration);
}
 
開發者ID:justinbaby,項目名稱:my-paper,代碼行數:21,代碼來源:FreemarkerUtils.java

示例11: generateHtmlPagination

import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer; //導入依賴的package包/類
/**
 * html分頁工具
 * @param allList			:	html分頁列表
 * @param pagesize			:	每頁顯示記錄數量
 * @param templatePathName	:	模板頁麵,完整地址 (相相對於freeamrker配置根目錄)
 * @param filePath			:	html文件,路徑目錄	--/-/
 * @param index				:	html文件,默認前綴	index
 */
private static void generateHtmlPagination(FreeMarkerConfigurer freemarkerConfig, List<?> allList, Map<String, Object> paramMap,int pagesize, String templatePathName , String filePath , String index){
	int allCount = allList!=null?allList.size():0;
	
	Map<String, Object> params = new HashMap<String, Object>();
	params.put("pageNumAll", 1);
	params.put("pageNum", 1);
	params.put("filePath", filePath);
	params.put("index", index);
	
	if (MapUtils.isNotEmpty(paramMap)) {
		params.putAll(paramMap);
	}
	
	if (allCount > 0) {
		int pageNumAll = allCount%pagesize==0 ? allCount/pagesize : allCount/pagesize + 1;
		for (int pageNum = 1; pageNum <= pageNumAll; pageNum++) {
			params.put("pageNumAll", pageNumAll);
			params.put("pageNum", pageNum);
			
			int from = (pageNum-1)*pagesize;
			int to = (from + pagesize) <= allCount ? (from + pagesize) : allCount;
			params.put("pageList", allList.subList(from, to));
			
			String fileName = (pageNum==1) ? index : (index + "_" + pageNum);
			HtmlTemplateUtil.generate(freemarkerConfig, params, templatePathName, filePath + fileName + ".html");
		}
	} else {
		params.put("pageNumAll", 0);
		HtmlTemplateUtil.generate(freemarkerConfig, params, templatePathName, filePath + index + ".html");
	}
}
 
開發者ID:xuxueli,項目名稱:xxl-incubator,代碼行數:40,代碼來源:HtmlGenerateServiceImpl.java

示例12: generateString

import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer; //導入依賴的package包/類
/**
 * 生成HTML字符串
 * 
 * @param content			: 頁麵傳參
 */
public static String generateString(FreeMarkerConfigurer freemarkerConfig, Map<?, ?> content, String templateName) {
	String htmlText = "";
	try {
		// 通過指定模板名獲取FreeMarker模板實例
		Template tpl = freemarkerConfig.getConfiguration().getTemplate(templateName);
		htmlText = FreeMarkerTemplateUtils.processTemplateIntoString(tpl, content);
	} catch (Exception e) {
		e.printStackTrace();
	}
	return htmlText;
}
 
開發者ID:xuxueli,項目名稱:xxl-incubator,代碼行數:17,代碼來源:HtmlTemplateUtil.java

示例13: freeMarkerConfigurer

import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer; //導入依賴的package包/類
@Bean
@ConditionalOnMissingBean(FreeMarkerConfig.class)
public FreeMarkerConfigurer freeMarkerConfigurer() {
	FreeMarkerConfigurer configurer = new FreeMarkerConfigurer();
	applyProperties(configurer);
	return configurer;
}
 
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:8,代碼來源:FreeMarkerAutoConfiguration.java

示例14: customFreeMarkerSettings

import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer; //導入依賴的package包/類
@SuppressWarnings("deprecation")
@Test
public void customFreeMarkerSettings() {
	registerAndRefreshContext("spring.freemarker.settings.boolean_format:yup,nope");
	assertThat(this.context.getBean(FreeMarkerConfigurer.class).getConfiguration()
			.getSetting("boolean_format")).isEqualTo("yup,nope");
}
 
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:8,代碼來源:FreeMarkerAutoConfigurationTests.java

示例15: renderTemplate

import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer; //導入依賴的package包/類
@Test
public void renderTemplate() throws Exception {
	registerAndRefreshContext();
	FreeMarkerConfigurer freemarker = this.context
			.getBean(FreeMarkerConfigurer.class);
	StringWriter writer = new StringWriter();
	freemarker.getConfiguration().getTemplate("message.ftl").process(this, writer);
	assertThat(writer.toString()).contains("Hello World");
}
 
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:10,代碼來源:FreeMarkerAutoConfigurationTests.java


注:本文中的org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。