REST - 在没有休眠的情况下获取新创建的资源

时间:2016-07-30 14:49:19

标签: spring spring-mvc spring-rest

我正在使用Spring MVC和 NamedParameterJdbcOperations

我正在进行休息调用以创建一个对象,我想返回这个新创建的对象。

无论使用何种数据库,如何返回新创建的对象?

我没有使用hibernate。在hibernate中,可以立即返回持久化对象。但是我希望在没有休眠的情况下实现这一点。

1 个答案:

答案 0 :(得分:0)

我使用 NamedParameterJdbcOperations 的update方法获取新创建的对象的密钥,然后使用此密钥获取对象。

获取密钥 -

GeneratedKeyHolder holder = new GeneratedKeyHolder();

namedParameterJdbcOperations.update(sql,sqlParameterSource,holder);
int key = holder.getKey().intValue();
相关问题