mybatis返回自增主键问题踩坑

1 <insert id="insert" keyProperty="id" useGeneratedKeys="true"
 parameterType="com.demo.domain.User">

2 insert into User_t(name,age,addr) values(#{name},#{age},#{addr})
3 </insert>

/**
service中获取 在controller中不起作用(大坑)
**/
public int insert(User user) {
        int insertNum = Integer.parseInt(userMapper.insert(user) + "");
        Long id = user.getId();//该对象的自增ID
        return id;
    }




posted @ 2019-01-31 10:47  洞玄巅峰  阅读(857)  评论(0编辑  收藏  举报