转mybatis 获取自增id
Posted devin.ding
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了转mybatis 获取自增id相关的知识,希望对你有一定的参考价值。
转自:http://www.cnblogs.com/rhythmK/p/4047142.html
1、环境:
mybatis : 3.2.3
spring-mybatis: 1.2.1
mysql:5.5.29
实体:
public class sys_user {
private int userid;
private String username;
public int getUserid() {
return userid;
}
public void setUserid(Integer userid) {
this.userid = userid;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username == null ? null : username.trim();
}
insert 节点配置:
<insert id="insert" parameterType="com.mamaguwen.entity.sys_user" useGeneratedKeys="true" keyProperty="userid">
<!-- <selectKey keyProperty="userid" resultType="int" order="BEFORE">
SELECT LAST_INSERT_ID() as userid
</selectKey> -->
insert into sys_user ( UserName)
values (#{username})
</insert>
keyProperty:对应为实体字段值
调用代码:
sys_UserDao.insert(model);
System.out.println("getUserid:"+ model.getUserid());
以上是关于转mybatis 获取自增id的主要内容,如果未能解决你的问题,请参考以下文章