Request Body with Content-Type: application/x-www-form-urlencoded;charset=UTF-8 Not working

1.4k Views Asked by At

How to have post mapping in controller, when content type is application/x-www-form-urlencoded;charset=utf-8 and request body has text or application/json. I have read that @requestbody does not work with urlencoded. How to reslove this issue.

1

There are 1 best solutions below

0
On
@CrossOrigin
@ResponseBody
@PostMapping
public Book addBook(@RequestBody Book newBook){
    Book book = new Book(newBook.getTitle());
    bookRepository.save(book);
    return book;
}

An example, it works