Sunday 17 September 2017

Spring MVC bad request(400) error

jquery-3.2.1.min.js:4 POST http://localhost:8080/jingles/saveFaculityDetails?faculityDetails=firstName=&lastName=&dateOfBirth=&qualification=&dateOfJoining=&designation=&specialization=&monthlyPay= 400 (Bad Request)

After a long time exploring my code I found the solution, If you are dealing with code like

@RequestMapping(value = "/saveFaculityDetails", method = RequestMethod.POST)
public @ResponseBody String saveFaculityDetails(@ModelAttribute("faculityDetails") FaculityDetailsDto faculityDetails , MultipartHttpServletRequest request) {

Please provide values to fields are related to Number class in java please provide value to all fields otherwise it will get default value as null which is primitive type for integer, this is reason you will get bad request error.

Please share your feedback for same.