1. 先引入Mybatis-Plus的依赖,把下面复制到pom文件中
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.3.1.tmp</version>
</dependency>
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity</artifactId>
<version>1.7</version>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-generator</artifactId>
<version>3.3.1.tmp</version>
</dependency>
2. 条件参数QueryWrapper的使用
- 创建QueryWrapper
QueryWrapper wrapper=new QueryWrapper();
- 常用方法,根据需求选择使用
wrapper.orderByDesc();
wrapper.select("relation_id, count(*) AS 'quantity'");
wrapper.eq("id",1);
wrapper.between("create_time","2021-01-02","2021-07-09");
wrapper.like("name","旭");
wrapper.last("LIMIT 0, 5 ");
3. 常用baseMapper方法
baseMapper.selectCount(wrapper);
baseMapper.selectById("1");
baseMapper.selectList(wrapper);
baseMapper.insert(entity);
baseMapper.delete(wrapper);
baseMapper.deleteById("1");
baseMapper.selectPage(Page,wrapper);
baseMapper.selectOne(wrapper);
baseMapper.updateById(Customers);