关于freemarker自定义标签作为模板在struts中生成静态html的问题
这个问题其实之前也已经有人问过了类似的:http://bbs.csdn.net/topics/320155882
,但是我还是找不到满意的答案。
详细描述如下:
自定义标签 [@vcms_entity][/@vcms_entity],这个标签只有三个参数,entity,package,id,传入这三个参数后可到数据库取出相应的对象
// + className + """);}
// }
// 保存结果集
env.setVariable(RESULT, ObjectWrapper.DEFAULT_WRAPPER.wrap(obj));
if (body != null) {
body.render(env.getOut());
}
}
@Autowired
public void setBasicService(BasicService basicService) {
this.basicService = basicService;
}
}
@Component
public class StaticFreemarker {
/**
* 初始化模板引擎
*
* @param ftl
* 模板名称
* @param htmlName
* 需要生成html页面的名称
* @param map
* 模板中需要的参数集合
* @param relativePath
* 模板相对于根路径的相对路径, 例如:/WebRoot/module/test.ftl,则这里传入的参数是module
* @throws IOException
* @throws TemplateException
*/
@SuppressWarnings("rawtypes")
public void init(String ftl, String htmlName, Map map, String relativePath)
throws IOException, TemplateException {
// 获取模板
Configuration cfg = new Configuration();
cfg.setServletContextForTemplateLoading(
ServletActionContext.getServletContext(), "/" + relativePath);
cfg.setEncoding(Locale.getDefault(), "utf-8");
Template template = cfg.getTemplate(ftl);
// 设置模板编码
template.setEncoding("utf-8");
String path = ServletActionContext.getServletContext().getRealPath("/");
File htmlFile = new File(path + htmlName);
Writer out = new BufferedWriter(new OutputStreamWriter(
new FileOutputStream(htmlFile), "utf-8"));
template.process(map, out);
out.flush();
out.close();
}
}
[@vcms_list entity="User" package="com.vcms.cms.entity" size=20 page=2 snames="birthday,registerTime"
svalues="2013-02-11,2013-02-13 23:08:32"]
[#list resultset.list as user]
<hr>
${user.userId}
<br>
${user.userName}
<br>
${user.registerTime}
<br>
${user.birthday}
<br>
[/#list]
[/@vcms_list]
freemarker struts html 自定义标签
[解决办法]
Expression obj is undefined on line 5, column 11 in a.ftl.第五行是什么?
报错意思表达式为定义。看看是否字母啥的,写错没有