How do I get Key without Object?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

How do I get Key without Object?

A浩酱
My project never use Object Entity.

My Mybatis Version is 3.4.0.
I write code to register.
The code like this:

int register(@Param("id") Integer id, @Param("name") String name, @Param("phone") String phone);
<insert id="register" parameterType="IDataSet" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
     INSERT INTO user (name, phone)  VALUES (#{name}, #{phone}); 
</insert>

I want to get Key So I use id param.
But It can't return Key.

How can I get Key?
I think org.apache.ibatis.binding.MapperMethod.convertArgsToSqlCommandParam method is important to solve this problem. Thank you for help!

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How do I get Key without Object?

Erwan Letessier
You have to pass a single object or map with those 3 properties/keys.
Indeed "keyProperty" denotes the target property hold by parameter object.

With named parameters in the Mapper,  I guess you cannot. It is actually resolved as a map by Mybatis but there is no pointer in your code to retrieve it.

Erwan

On Thu, May 10, 2018, 10:39 A浩酱 <[hidden email]> wrote:
My project never use Object Entity.

My Mybatis Version is 3.4.0.
I write code to register.
The code like this:

int register(@Param("id") Integer id, @Param("name") String name, @Param("phone") String phone);
<insert id="register" parameterType="IDataSet" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
     INSERT INTO user (name, phone)  VALUES (#{name}, #{phone}); 
</insert>

I want to get Key So I use id param.
But It can't return Key.

How can I get Key?
I think org.apache.ibatis.binding.MapperMethod.convertArgsToSqlCommandParam method is important to solve this problem. Thank you for help!

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.