1、依赖和版本
我的mybatis-plus版本是3.0.6 springboot是2.1.2
需要导入mybatis-plus依赖
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.0.6</version>
</dependency>
2、mapper
mapper中不需要代码,继承BaseMapper就好
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
public interface TestMapper extends BaseMapper<实体类> {
}
3、service
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
/**
* 服务实现类
* @author
*/
@Service
public class ExGaViolateReportServiceImpl extends ServiceImpl<ExGaViolateReportMapper, ExGaViolateReport> implements ExGaViolateReportService {
@Override
public IPage selectPage(IPage<ExGaViolateReport> page, QueryWrapper<ExGaViolateReport> wrapper) {
return baseMapper.selectPage(page,wrapper);
}
}
4、controller
@Autowired
private ExGaViolateReportService exGaViolateReportService;
@ResponseBody
@RequestMapping(value = "/record")
public Object recordInfo(String cardNum,int pageNum,int pageSize){
//添加查询参数
QueryWrapper<ExGaViolateReport> wrapper = new QueryWrapper<>();
wrapper.eq("card_num",cardNum);
//添加分页
IPage<ExGaViolateReport> page = new Page<>(pageNum,pageSize);
IPage<实体类> list = testService.selectPage(page,wrapper);
return list;
}
注意这边的IPage<ExGaViolateReport> page = new Page<>(pageNum,pageSize);中new Page导入的包是
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;