我在浏览器中遇到415错误。我无法找到错误。能帮忙吗?
$ scope.user = {email:“admin”,密码:“password”};
$http.post('/expense-manager-api/login/authenticate', $scope.user, {
headers: {"Content-Type": "application/json"}
}).success(function(login) {
$scope.setError(login.status);
$location.path("main");
}).error(function() {
$scope.setError('Invalid user/password combination');
});
@Controller
@RequestMapping("/login")
public class LoginController {
@RequestMapping(value = "/authenticate", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
public
@ResponseBody
LoginResponse login(@RequestBody LoginRequest loginRequest) {
if (loginRequest.getEmail().equals("admin") && loginRequest.getPassword().equals("password")) {
UUID uuid = UUID.randomUUID();
return new LoginResponse(uuid.toString(), "OK");
}
return new LoginResponse(null, "Invalid user/password combination");
}
}
答案 0 :(得分:0)
杰克逊映射器解决了这个问题。
在你的pom.xml中添加Jackson-mapper的maven依赖