Mybatis @Insert插入数据返回自增的主键id

mapper层

    @Insert("insert into t_user (username,password,valid,create_time) values (#{username},#{password},#{valid},#{createTime})")
    @Options(useGeneratedKeys=true, keyProperty="id", keyColumn="id")
    int add(User user);
​

 

获取返回的id

User user = new User();
user.setUsername("测试");
​
userMapper.add(user);
​
System.out.println("用户的自增id为"+user.getId());

 

 

上一篇:Android仿iPhone晃动撤销输入功能(微信摇一摇功能)


下一篇:好用的npm包