Ajax传输数据request.getParameter("key")获取为空
兄弟,用map接收,然后封装到user表里吧。
下面部分代码
var data = { sno:sno, password:password, verifyCode:verifyCode, status:status } $.ajax({ type: 'Post', url: "/DormController/checkLogin", contentType:"application/json", data: JSON.stringify(data), dataType: "text", //返回数据类型 success: function (msg) { if ("success" == msg) { window.location.href = "/DormController/index"; } else { $.messager.alert("消息提醒", msg, "warning"); $("#vcodeImg").click();//切换验证码 $("input[name='vcode']").val("");//清空验证码输入框 } } });
@ResponseBody @RequestMapping("/checkLogin") public String checkLogin(@RequestBody Map<String, String> map, HttpSession session) { if (!map.get("verifyCode").equals(session.getAttribute("verify"))) { return "验证码不正确"; } List<User> users = userService.findUserByStatus(Integer.parseInt(map.get("status"))); System.out.println("sno---->"+map.get("sno")); if (Integer.parseInt(map.get("status")) == 1) { //超级管理员用户 for (User user1 : users) { if (user1.getSno().equals(map.get("sno")) && user1.getPassword().equals(map.get("password"))) { session.setAttribute("user", user1); return "success"; } } return "用户名或密码不正确!"; } }