Java – spring HATEOAS resourcesupport – > domain object
•
Java
When using service objects, we use the toresource method to convert them into resources, and on the way back (publishing the resource representation from the client to the server), how to convert the representation back to the domain object?
I want to construct the book (@ entity) class from the bookresource (extended resourcesupport) class
@RequestMapping(path="/",method = RequestMethod.POST,produces="application/vnd.company.app.book-v1+hal+json") public ResponseEntity<?> addBook(@RequestBody BookResource bookResource) { //What to do here? }
Solution
Your bookresource should extend resource instead of resourcesupport
public class BookResource extends Resource<Book> { public BookResource(Book content,Link... links) { super(content,links); } }
In this way, you can get the getcontent () method for free, that is, "return the underlying entity"
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码