mybatis 插入

实体类

Mapper接口
    void  addUser(User user);
Mapper.xml
<insert id="addUser" useGeneratedKeys="true" keyProperty="id">
insert into user_t(user_name,password,age)
values(#{userName},#{password},#{age})
</insert>

如果你的数据库支持自动生成主键的字段(比如 MySQL 和 SQL Server),那么你可以设置 useGeneratedKeys=”true”,然后再把 keyProperty 设置到目标属性上就OK了。
这样插入的实体可以获得ID了。
posted @ 2017-04-06 16:41  Always_July  阅读(157)  评论(0编辑  收藏  举报