415-不支持的媒体类型错误| angularjs + Spring3.2

时间:2014-08-08 17:36:57

标签: angularjs web-services spring-mvc http-post http-status-code-415

我在浏览器中遇到415错误。我无法找到错误。能帮忙吗?

  • loginController.js

$ 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');
});
  • LoginController.java

@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");
}

}

Network Call

request and response headers

1 个答案:

答案 0 :(得分:0)

杰克逊映射器解决了这个问题。

在你的pom.xml中添加Jackson-mapper的maven依赖