jsp
html
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<body>
<h2>Hello World!</h2>
<!-- rest风格 -->
<a href="users/add5/1/zhangsan">添加5</a>
<!-- ant风格-->
<a href="users/aa/add6">添加6</a>
</body>
</html>
java
java
package com.test.controller;
import com.test.pojo.Users;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import javax.servlet.http.HttpServletRequest;
@Controller
@RequestMapping("/users")
public class UsersController {
//方式4
@RequestMapping("/add5/{id}/{name}")
public String add5(@PathVariable(value="id") int id,@PathVariable(value="name") String name)
{
System.out.println(id);
System.out.println(name);
return "success";
}
//方法5
/*
**:匹配任意路径
* :匹配任意字符 0个或任意个
?:匹配一个任意字符
*/
@RequestMapping("/**/?dd6")
public String add6()
{
return "success";
}
}