Mapper Example学习
起因: 在公司实习时发现,公司所使用的Mybatis逆向工程生成的代码和Mapper.xml文件与自己常用的逆向工程生成器生成的不一样
公司Mybatis逆向工程生产以下产物:
名称 | 描述 | 作用 |
---|---|---|
XxxMapper.xml | Mybatis配置文件 | 配置SQL语句 |
XxxMapper.class | Mapper接口 | 对应每个SQL语句 |
XxxMapping.class | 实体类 | 对应数据库表中的每个字段,一个实体类代表一行数据 |
XxxMappingExample.class | SQL语句类 | 配置各种SQL条件 |
一、Mapper方法介绍:
方法名称 | 作用 |
---|---|
int countByExample(XxxMappingExample example); | 按条件计数 |
int deleteByExample(XxxMappingExample example); | 按条件删除 |
int deleteByPrimaryKey(Integer id); | 按主键删除 |
int insert(XxxMapping record); | 插入一行数据 |
int insertSelective(XxxMapping record); | 插入一行数据(某些字段可以为空) |
List selectByExample(XxxMappingExample example); | 按条件查询 |