文章目录
- 一、mapper的crud方法:
- 1. selectByPrimaryKey(id)
- 2. selectByExample(example)
- 3. selectCountByExample(example)
- 4. updateByPrimaryKey(User user)
- 5. updateByPrimaryKeySelective(User user) (建议使用)
- 6. updateByExample(User user,Example example)
- 7. updateByExampleSelective(User user,Example example) (建议使用)
- 8. deleteByPrimaryKey(id)
- 9. deleteByExample(example)
- 10. insert(User user)
- 11. insertSelective(User user) (推荐使用)
一、mapper的crud方法:
1. selectByPrimaryKey(id)
根据主键查询,返回的是个对象
mapper.selectByPrimaryKey(id)
2. selectByExample(example)
根据条件查询,返回的是一个list,下面的and/or方法测试用的就是这个
mapper.selectByExample(example)
3. selectCountByExample(example)
根据条件查询后计数,返回的是int
mapper.selectCountByExample(example)
4. updateByPrimaryKey(User user)
根据主键修改,返回的是int
mapper.updateByPrimaryKey(user)
5. updateByPrimaryKeySelective(User user) (建议使用)
根据主键修改不为null的字段,返回的是int
mapper.updateByPrimaryKeySelective(user)
6. updateByExample(User user,Example example)
根据条件修改,返回的是int,注意:前面的参数user是要修改的内容,后面的example是查询条件,查到结果后将结果按user的值修改
mapper.updateByExample(user, example)
7. updateByExampleSelective(User user,Example example) (建议使用)
根据条件修改不为null的字段,返回的是int
mapper.updateByExampleSelective(user, example)
8. deleteByPrimaryKey(id)
根据主键删除,返回的是int
mapper.deleteByPrimaryKey(id)
9. deleteByExample(example)
根据条件删除,返回的是int
mapper.deleteByExample(example)
10. insert(User user)
插入一条数据,返回值是id
mapper.insert(User user)
11. insertSelective(User user) (推荐使用)
插入一条数据,值为null的字段会做判空操作,不会添加
mapper.insertSelective(user)