// 假设页面请求有两个参数:userId 和 password
$.ajax({
url: 'sysUser/doUnlock',
type: 'post',
data: {userId:'用户编号',password:'用户密码'},
dataType: 'json',
success: function (res) {
}
});
// 我们看看后端可以用什么方式接收参数?
// 第一种方式
// 我们使用 HttpServletRequest 对象来获取参数的值
// request.getParameter("XX") 中 XX必须与请求中的参数名称一致,否则接收不到数据
@RequestMapping("/doUnlock")
public Map doUnlock(HttpServletRequest request){
try {
String userId = request.getParameter("userId");
String password = request.getParameter("password");
// 此处省略一万行代码
return resultSuccess();
} catch (Exception e) {
e.printStackTrace();
}
return resultError();
}
// 第二种方式
// 使用 @RequestParam注解 直接将参数值绑定声明的变量
// @RequestParam("XX")中,XX必须与请求中的参数名称一致,后面声明的变量不做强制要求ÿ