Why am I getting 400 requests with AngularJs?

I am using Spring MVC and AngularJs to build a web application. I send a request to the server, but I get 400 error bad request . I am setting up a message converter for the json format in the Spring servlet configuration file. I am wondering why I am getting this error.

Here is my angular service:

 save : function(user) { return $http({ method: 'POST', url: '/app-web/user/create', contentType: "application/json", data:user }); } 

And on the server side, I have a Spring MVC controller, as described below:

 @RequestMapping(value="/user/create", method= RequestMethod.POST) @ResponseBody public String createAccount(@RequestBody User user){ //some logic return "Ok"; } 

I noticed something else: when I delete @RequestBody in the controller, I don't have a 400 error, but the user is null :

 @RequestMapping(value="/user/create", method= RequestMethod.POST) @ResponseBody public String createAccount(User user){ //some logic return "Ok"; } 
+7
java spring angularjs spring-mvc
source share
1 answer

The problem was in the user form. I had a name, name, email address, password, password1, but the custom Java object does not contain the password1 attributes. When the json data provided by the request does not match the Java object, the JsonConverter cannot match the data in the Java Object.

+4
source share

All Articles