Spring code
@RequestMapping(value="/users",method=RequestMethod.POST,headers = "content-type=application/json;application/x-www-form-urlencoded; charset=UTF-8")
public @ResponseBody String addNewCinemaCampaign( @RequestBody @Valid User user)
{
System.out.println(user!=null?user.getName():"Null");
return userService.createUser(user);
}
I am creating new user via Angular post method but I am getting always 415 unsupported media type. Please resolve this problem...
I think it will be helpful in your case:
produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE
So in your code it will be
@RequestMapping(value="/users",method=RequestMethod.POST,produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
public @ResponseBody String addNewCinemaCampaign( @RequestBody @Valid User user)
{
System.out.println(user!=null?user.getName():"Null");
return userService.createUser(user);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.