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; }