简体   繁体   中英

Post with Jax-RS

This really should be a simple question, and I apologize but I just can't seem to find the answer. From my understanding you can take in an object and have it use say a bean in Java EE to produce this Object/Entity into a database. Now the problem is the ID is going to be auto-generated so the client will not know this when first being created. How do I return with the @POST in Jax-RS what there now provided URI/ID location is so they know who they are provided that ID after being created. I have read and thought this was possible but maybe I am wrong, if someone could point me in the direction of my solution.

This really doesn't have much to do with REST, this is a JPA question. The EntityManager 's merge and persist will return a managed entity. It will have the id/key in it. Just return that in the @POST .

为什么不能发送响应中填充了id的json对象?

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM