| tk.mybatis | mybatis-plus:service接口 | mybatis-plus:mapper接口 | |
查询 | | | | |
| T selectByPrimaryKey | T getById | T selectById | |
| int selectCount | int count | Integer selectCount | |
| List<T> selectByExample | List<T> list() | List<T> selectList | |
| int selectCountByExample | | Integer selectCount | |
| T selectOneByExample | T getOne | T selectOne | |
| List<T> selectAll | List<T> list() | List<T> selectList | |
| boolean existsWithPrimaryKey | | | |
| T selectOne | T getOne | T selectOne | |
| List<T> selectByIds | Collection<T> listByIds | List<T> selectBatchIds | 根据主键字符串进行查询,类中只有存在一个带有@Id注解的字段 |
| | | | |
新增 | | | | |
| int insert | | int insert | |
| int insertSelective | boolean save | int insert | 保存一个实体,null的属性不会保存,会使用数据库默认值 |
修改 | | | | |
| int updateByPrimaryKey | | int updateById | |
| int updateByPrimaryKeySelective | boolean updateById | int updateById | 根据主键更新属性不为null的值 |
| int updateByExample | | int update | |
| int updateByExampleSelective | boolean update | int update | |
删除 | | | | |
| int deleteByPrimaryKey | boolean removeById | int deleteById | |
| int delete | boolean remove | int delete | |
| int deleteByIds | boolean removeByIds | int deleteBatchIds | 根据主键字符串进行删除,类中只有存在一个带有@Id注解的字段 |
| int deleteByExample | boolean removeByMap | int deleteByMap | |
批量操作 | | | | |
| insertList | boolean saveBatch | | |
| updateListByPrimaryKeySelective | boolean updateBatchById | | |
| updateByPrimaryKeySelectiveForce | update(updateWrapper) | | |
| updateByExampleSelectiveForce | update(updateWrapper) | | |
| | | | |
分页 | | | | |
| pageHelper | IPage<T> page | | |
扩展 | | | | |
| | alwaysUpdateSomeColumnById | | 根据 ID 更新固定的那几个字段(但是不包含逻辑删除) |
| | insertBatchSomeColumn | | 批量新增数据,自选字段 insert |
| | deleteByIdWithFill | | 根据 id 逻辑删除数据,并带字段填充功能 |
排序 | | | | |
| searchCriteria.setExampleOrderByClause(example, BlackList.class); | orderByAsc(boolean condition, R... columns) | | |
| | | | |
条件构造 | | | | |
| Example | QueryWrapper | | |
| | 查询方式 | | 说明 |
| | select | | 设置查询字段 |
| | and | | AND 语句,拼接 + AND (字段=值) |
| | or | | OR 语句,拼接 + OR (字段=值) |
| | eq | | 等于= |
| | allEq | | 基于 map 内容等于= |
| | ne | | 不等于<> |
| | gt | | 大于> |
| | ge | | 大于等于>= |
| | lt | | 小于< |
| | le | | 小于等于<= |
| | like | | 模糊查询 |
| | notLike | | 模糊查询 NOT LIKE |
| | in | | IN 查询 |
| | notIn | | NOT IN 查询 |
| | isNull | | NULL 值查询 |
| | isNotNull | | IS NOT NULL |
| | groupBy | | 分组 GROUP BY |
| | having | | HAVING 关键词 |
| | orderBy | | 排序 ORDER BY |
| | orderAsc | | ASC 排序 ORDER BY |
| | orderDesc | | DESC 排序 ORDER BY |
| | exists | | EXISTS 条件语句 |
| | notExists | | NOT EXISTS 条件语句 |
| | between | | BETWEEN 条件语句 |
| | notBetween | | NOT BETWEEN 条件语句 |
| | last | | 拼接在最后,例如:last(“LIMIT 1”) |