freemarker

freemaker常见语法(二)

时光毁灭记忆、已成空白 提交于 2019-12-06 15:00:51
以下内容全部是网上收集: FreeMarker的模板文件并不比HTML页面复杂多少,FreeMarker模板文件主要由如下4个部分组成: 1,文本:直接输出的部分 2,注释:<#-- ... -->格式部分,不会输出 3,插值:即${...}或#{...}格式的部分,将使用数据模型中的部分替代输出 4,FTL指令:FreeMarker指定,和HTML标记类似,名字前加#予以区分,不会输出 下面是一个FreeMarker模板的例子,包含了以上所说的4个部分 <html><br> <head><br> <title>Welcome!</title><br> </head><br> <body><br> <#-- 注释部分 --><br> <#-- 下面使用插值 --> <h1>Welcome ${user} !</h1><br> <p>We have these animals:<br> <u1><br> <#-- 使用FTL指令 --> <#list animals as being><br> <li>${being.name} for ${being.price} Euros<br> <#list><br> <u1><br> </body><br> </html> 1, FTL指令规则 在FreeMarker中,使用FTL标签来使用指令,FreeMarker有3种FTL标签

Handling FreeMaker template with Ktor Kotlin

本小妞迷上赌 提交于 2019-12-06 14:12:01
I'm very new to Kotlin (and Java), as well as Ktor and FreeMaker , trying to make an app combining all of them, but looks I'm doing something wrong related to the FreeMaker templates manipulating. My app structure is: template.ftl : <#macro mainLayout title="Welcome"> <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>${title} | Kweet</title> </head> <body> HI </body> </html> </#macro> index.ftl : <#import "template.ftl" as layout /> imported title: ${title} <@layout.mainLayout title="Welcome"> <div class="posts"> <h3 class="content-subhead

Mybatis的Environment解析详解

不羁岁月 提交于 2019-12-06 12:17:48
今天来具体看一下如何解析environments //XMLConfigBuilder Java代码 private void parseConfiguration(XNode root) { try { propertiesElement(root.evalNode( "properties" )); typeAliasesElement(root.evalNode( "typeAliases" )); pluginElement(root.evalNode( "plugins" )); objectFactoryElement(root.evalNode( "objectFactory" )); objectWrapperFactoryElement(root.evalNode( "objectWrapperFactory" )); settingsElement(root.evalNode( "settings" )); //解析environments environmentsElement(root.evalNode( "environments" )); databaseIdProviderElement(root.evalNode( "databaseIdProvider" )); typeHandlerElement(root.evalNode(

freemarker与JSP在同一页面中使用

谁说我不能喝 提交于 2019-12-06 10:10:23
先申明, 这个实践非常不好, 只有在某些时间确实需要这玩意的时候才使用. 原理很简单, 使用HTML的注释<!--内容--> 因为JSP的注释是<%--内容--%>, freemarker的注释是<#--内容-->, 而JSP/freemarker的标签在<!--内容-->中时, 是可以被正常解析的, 而不支持的标签则会原样输出. <!-- <%@ page contentType="text/html;charset=UTF-8" language="java" %> <#assign surekam=JspTaglibs["/WEB-INF/part.tld"]> <#assign test=' Freemarker '/> <c:set var="test" value= "jsp"/> --> ${test} 这里的test在JSP中将会输出JSP, 而freemarker中将会输出freemarker, 但是, 上面JSP中会留下 <!-- <#assign surekam=JspTaglibs["/WEB-INF/part.tld"]> <#assign test=' Freemarker '/> --> 在freemarker中会留下 <!-- <%@ page contentType="text/html;charset=UTF-8" language="java"

How can I embed one DropWizard (with freemarker) View in another one?

淺唱寂寞╮ 提交于 2019-12-06 10:08:22
I am using DropWizard and Freemarker to build up a view which displays different types of forms based on results from a webservice. I have created the forms as views - each with their own ftl. So, in my resource, I discover which form I need, then load the main.ftl, passing the form view as a parameter (see below). This doesn't work. Can anyone see where we're going wrong? Or is there a completely different way to chain views together using DropWizard and freemarker? @GET public Form getForm() { FormView view = new FormView(service.getForm()); return new MainView(view); } public class FormView

How to access a Spring application property in a Freemarker template?

梦想的初衷 提交于 2019-12-06 08:57:39
I have Java webapp that uses Spring 3.1, with Freemarker templates for rendering the view. I want to conditionally display a link in the view, based on the true/false value of a particular application property. I have the following app property defined in src/main/resources/application.properties : showLink=true If I were using a regular JSP with Spring MVC, I could use SpEL to conditionally display the link based on the value of showLink : <c:if test="${configuration['showLink']}"> <a href="...">some link</a> </c:if> How do I do this in a Freemarker template? I tried doing something like this

How to check the existense of a freemarker template before include it

可紊 提交于 2019-12-06 08:48:36
Sometimes I have to use the following snippet : <#include 'some.ftl' /> Does freemarker have a directive that return the existense of some.ftl ? Like <#include_if_exists 'some.ftl' > Or can I implement such a directive by myself? OK. Resolved by user-directive [@include template='some.ftl' /] WARN if template not found... import java.io.FileNotFoundException; import java.io.IOException; import java.util.Map; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import freemarker.core.Environment; import freemarker.template.Template; import freemarker.template.TemplateDirectiveBody; import

Hello FreeMarker

天大地大妈咪最大 提交于 2019-12-06 07:43:18
官方地址: http://www.freemarker.org/ 下载地址: http://sourceforge.net/projects/freemarker/files/freemarker/2.3.18/freemarker-2.3.18.tar.gz/download 1.解压后:freemarker-2.3.18\examples\webapp2 拷贝到tomcat的webapps下修改help.html 中有地址 <a href="index.a"><code>http://<i>yourServer</i>/<i>thisWebApp</i>/index.a</code></a> 为自己服务器地址; 2.将freemarker-2.3.18\lib拷贝到 freemarker-2.3.18\examples\webapp2的lib里 启动,则可以看到demo示例运行 来源: oschina 链接: https://my.oschina.net/u/94965/blog/38689

使用Freesql简单地实现多条件查询

ぃ、小莉子 提交于 2019-12-06 07:43:04
在实际应用中我们经常会遇到多条件查询的情景,以往的解决方案是在java中对各个参数值进行非空之类的判断,再进行sql及参数的拼凑。 其实还有更简单的解决方法的--用Freemarker。Freemarker可以轻松的使用if之类的进行判断,当if条件时再使用指定的sql片段。而Freesql就是在Freemarker的基础上,配合java中sql的参数设置进行的简单封装,可以简单方便的编写动态的sql。 如何使用Freesql 本文介绍如何在JFinal中使用Freesql。Freesql的jar包可以从 http://git.oschina.net/jse7en/Freesql/ 中下载。Freesql默认提供对JFinal的支持,在JFinal中可以简单的使用JFinal。 初始化Freesql 在JFinalConfig中添加Freesql插件 public class ProjectConfig extends JFinalConfig { //... @Override public void configPlugin(Plugins me) { //Freesql默认使用web根目录下的freesql作为模板存放根目录 FreesqlPlugin freesql = new FreesqlPlugin(); /

freemarker cannot handle request for '/' on google app engine

允我心安 提交于 2019-12-06 06:55:47
问题 I'm trying to get freemarker working under Google App Engine. I've gotten simple ftl template files working when requested directly however I'd like to have index.ftl work if available otherwise index.html -- or vice versa. If I request /index.html , it renders fine as HTML. If I request /index.ftl , it renders fine as a FreeMarker template. Variables are expanded. If, however, I request '/' it gives the following 404 message: Problem accessing /index.html/index.ftl. I have the following in