创建MyBatisPlus配置类
package com.yootk.provider.config;
import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class MyBatisPlusConfig {
@Bean
public MybatisPlusInterceptor getMybatisPlusInterceptor() {
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
interceptor.addInnerInterceptor(
new PaginationInnerInterceptor(DbType.MYSQL));
return interceptor;
}
}
创建IDeptDAO数据接口
package com.yootk.provider.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yootk.provider.vo.Dept;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface IDeptDAO extends BaseMapper<Dept> {
}
在生产端需要提供有业务接口的实现子类
@Service
public class DeptServiceImpl implements IDeptService {
@Autowired
private IDeptDAO deptDAO;
@Override
public Map<String, Object> split(int currentPage, int lineSize, String column, String keyword) {
QueryWrapper<Dept> wrapper = new QueryWrapper<>();
wrapper.like(column, keyword);
int count = this.deptDAO.selectCount(wrapper);
IPage<Dept> page = this.deptDAO.selectPage(new Page<>(currentPage, lineSize, count), wrapper);
Map<String, Object> map = new HashMap<>();
map.put("allDepts", page.getRecords());
map.put("allRecorders", page.getTotal());
map.put("allPages", page.getPages());
return map;
}
}