1.在href里写上username=hehe
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
</head>
<body>
<%--请求参数绑定--%>
<a href="param/testParam?username=hehe">请求参数绑定</a>
</body>
</html>
2.在方法参数里加上username,会自动传进去
@Controller
@RequestMapping("/param")
public class ParamController {
@RequestMapping("/testParam")
public String testParam(String username){
System.out.println("执行了...");
System.out.println("用户名:"+username);
return "success";
}
}
3.还可以穿多个参数
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
</head>
<body>
<%--请求参数绑定--%>
<a href="param/testParam?username=hehe&password=123">请求参数绑定</a>
</body>
</html>
@Controller
@RequestMapping("/param")
public class ParamController {
@RequestMapping("/testParam")
public String testParam(String username,int password){
System.out.println("执行了...");
System.out.println("用户名:"+username);
System.out.println("密码:"+password);
return "success";
}
}
![在这里插入图片描述](https://img-blog.csdnimg.cn/20190324203325478.png)