标签:style blog http color java os io 2014
java 中实现/user/edit?id=${id}=${type} 的替换;
引入包: freemark.jar ,以及
public class FreeMarkerTextTemplateUtils { public static String processTextTemplateToString(String textTemplate, Object model) throws IOException, TemplateException { Configuration cfg = new Configuration(); StringTemplateLoader loader = new StringTemplateLoader(); String name = "kk_tempate"; loader.putTemplate(name, textTemplate); cfg.setTemplateLoader(loader); Template template = cfg.getTemplate(name); return FreeMarkerTemplateUtils.processTemplateIntoString(template, model); } }
单元测试代码如下:
String url="/user/edit?id=${id}&&type=${type}";
HashMap<String,Object> modelMap=new HashMap<String,Object>();
modelMap.put("id", 1);
modelMap.put("type", 1);
FreeMarkerTextTemplateUtils.processTextTemplateToString(
url, modelMap);
输出入下:/user/edit?id=1&&type=1
spring mvc 用freemarker实现/user/edit?id=${id}=${type} 的替换,布布扣,bubuko.com
spring mvc 用freemarker实现/user/edit?id=${id}=${type} 的替换
标签:style blog http color java os io 2014
原文地址:http://www.cnblogs.com/jennybackup/p/3905369.html