angular2如何使用参数请求数据,并像这样弹簧@requestParam
或@requestBody
..
/**
* 后台账户登录
*
* @param userName userName
* @param password password
* @return result
*/
@RequestMapping(value = "login", method = RequestMethod.POST)
public AdminModel login(@RequestParam String userName, @RequestParam String password) {
AdminModel adminModel = service.findAdminUserByUserName(userName);
if (adminModel == null) {
return null;
}
if (MD5Util.encode(password, adminModel.getSalt()).equals(adminModel.getPassword())) {
return null;
}
return adminModel;
}
我已多次尝试过,但我无法得到正确的方法。
答案 0 :(得分:2)
使用URLSearchParams
。这会自动将 $json = array("result" => "success", "message" => "Method is post", "data" => $_POST);
echo json_encode($json);
设置为Content-Type
并将参数编码为正确的格式。
application/x-www-form-urlencoded