您的位置:首页 > 其它

mybatics 获取insert自增id的两种方法

2013-08-17 20:25 295 查看
一:在map.xml文件中增加:useGeneratedKeys="true" keyProperty="id"

例子:<insert id="insert" parameterType="com.target.infrastructure.db.model.Document" useGeneratedKeys="true" keyProperty="id">

二:在map.xml文件中增加:

<selectKey resultType="java.lang.Integer" order="AFTER" keyProperty="id">

SELECT LAST_INSERT_ID() AS ID

</selectKey>

例子:

<insert id="insert" parameterType="cn.***.beans.LogObject" >

<selectKey resultType="java.lang.Integer" order="AFTER" keyProperty="id">

SELECT LAST_INSERT_ID() AS ID

</selectKey>

INSERT INTO TableName ...

参考:

http://stackoverflow.com/questions/7205365/how-to-return-key-after-insert-using-mybatis-when-the-id-uuid-as-is-stored-as-bi

/article/7444320.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: