转载自:http://blog.csdn.net/csdn_gia/article/details/54982053
URL模版映射
主要是为请求restfull设计模式
Restfull软件架构设计模式:请求更间接,更安全,方便于搜索引擎收录
list.jsp:
- <body>
- <table border="1" style="color: blue">
- <tr>
- <td>姓名</td>
- <td>生日</td>
- <td>性别</td>
- <td>地址</td>
- <td>操作</td>
- </tr>
-
- <c:forEach items="${userList }" var="user">
- <tr>
- <td>${user.username }</td>
- <td>${user.birthday }</td>
- <td>${user.sex }</td>
- <td>${user.address }</td>
- <td>
- <a href="${pageContext.request.contextPath }/user/update.do?id= ${user.id}修改</a>
- </td>
- </tr>
- </c:forEach>
- </table>
- </body>
普通模式修改:
- <a href="${pageContext.request.contextPath }/user/update.do?id= ${user.id}修改</a>
代码:
- @RequestMapping("update")
- public String update(Integer id){
- System.out.println(id);
- return "redirect:list.do";
- }
url模版映射过程
url模版映射功能:
请求参数映射到{id}
{id}传递到方法里面的参数id
通过@Pathvariable把{id}传递到方法里面的id
利用servlet拦截请求目录功能,实现无扩展名真正的restfull风格
Restfull风格设计
- <a href="${pageContext.request.contextPath }/rest/user/updateByID/${user.id }">修改</a>
Web.xml拦截方式:在rest目录下所有请求都被拦截,servlet可以拦截目录。
- <servlet-mapping>
- <servlet-name>springmvc</servlet-name>
- <url-pattern>/rest/*</url-pattern>
- </servlet-mapping>
{}:匹配接受页面Url路径参数
@Pathariable:{}里面参数注入后面参数里面
- @RequestMapping("update/{id}")
- public String update(@PathVariable Integer id){
- System.out.println(id);
- return "redirect:user/list.do";
- }