After a single drop MyBatis returns the id of the self-energizing


<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());

    }     

}



Guess you like

Origin blog.51cto.com/14028890/2402824
Recommended