<insert id="insertUser" useGeneratedKeys="true" keyProperty="id" parameterType="com.xxxx.xxx.bean.User">
insert into user(name,age) values(#{name},#{age})
</insert>
useGeneratedKeys="true" keyProperty="id"
Expressed as a primary key id, and the auto-incremented (Note: You can only be of type int to increment, varchar will not do)
package com.xxxx.xxx.mapper;
@MapperScan
public interface XxxxMapper{
public Integer insertUser(User user);
}
@Service("userService")
public class userService implements UserService {
@Autowired
private XxxxMapper xxxxMapper;
public void insertUser(User user) throws Excetion{
xxxxMapper.insertUser(user);
// increment the returned id can not use the return value, you need the following:
logger.info("id="+user.getId());
}
}