- package com.wuwei.test;
- import org.marker.web.url.Parameter;
- import org.marker.web.url.URLRewrite;
- /**
- * 测试URL规则
- * */
- public class Test {
- public static void main(String[] args) {
- URLRewrite re = new URLRewrite();
- //设置规则参数
- re.ruleParameter.put("{channel}", new Parameter("p","{channel}","([a-zA-Z_0-9]+)"));
- re.ruleParameter.put("{type}", new Parameter("type","{type}","([a-zA-Z_0-9]+)"));
- re.ruleParameter.put("{id}", new Parameter("id","{id}","([0-9]+)"));
- //初始化两个规则
- re.putRule("列表","{channel}.html");
- re.putRule("内容","{channel}/{type}/cms-thread-{id}.html");
- //文章类型的地址
- String url ="p=index&type=article&id=1";
- System.out.println("访问的地址:"+url);
- System.out.println("-----------------------");
- String gourl = re.encoder(url);
- System.out.println("URL编码:"+gourl);
- gourl = re.decoder(gourl);
- System.out.println("URL解码:"+gourl);
- System.out.println("==========================");
- //栏目类型的地址
- url ="p=about";
- System.out.println("访问的地址:"+url);
- System.out.println("-----------------------");
- gourl = re.encoder(url);
- System.out.println("URL编码:"+gourl);
- gourl = re.decoder(gourl);
- System.out.println("URL解码:"+gourl);
- }
- }
- //该片段来自于http://www.codesnippet.cn/detail/1908201410255.html
来源: http://www.codesnippet.cn/detail/1908201410255.html