码迷,mamicode.com
首页 > 编程语言 > 详细

spring mvc 用freemarker实现/user/edit?id=${id}=${type} 的替换

时间:2014-08-11 21:00:12      阅读:423      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   java   os   io   2014   

java 中实现/user/edit?id=${id}=${type} 的替换;

引入包: freemark.jar  ,以及

bubuko.com,布布扣

类代码如下:
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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!