mybatis获取刚刚插入的数据的主键

代码如下:插入数据库的瞬时态返回吧  个人猜测。

@Service
public class UserService {
    @Autowired
    private UserMapper userMapper;

    @Autowired
    private UserMapperEx userMapperEx;
    public List<User> getUser(){
      return   userMapper.selectByExample(null);
    }
    public int inserAndgetId(User user){
        //int i = userMapperEx.insertAndgetId(user);
        int insert = userMapper.insert(user);
        System.out.println(user.getId());
        return  insert;
    }


}

相关的拓展理解:https://blog.csdn.net/rapier512/article/details/51198684

猜你喜欢

转载自blog.csdn.net/qq_40006446/article/details/82111041
今日推荐