用mybatis 自带IPage接口,不用自己写 数据库 limit 语法 来处理分页,实现跨数据库。
@AutoLog(value = "student_material_template-分页列表查询")
@ApiOperation(value="student_material_template-分页列表查询", notes="student_material_template-分页列表查询")
@GetMapping(value = "/list")
public Result<?> queryPageList(StudentMaterialTemplate studentMaterialTemplate,
@RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
@RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
HttpServletRequest req) {
/*QueryWrapper<StudentMaterialTemplate> queryWrapper = QueryGenerator.initQueryWrapper(studentMaterialTemplate, req.getParameterMap());
Page<StudentMaterialTemplate> page = new Page<StudentMaterialTemplate>(pageNo, pageSize);
IPage<StudentMaterialTemplate> pageList = studentMaterialTemplateService.page(page, queryWrapper);*/
//自定义查询分页,过滤卷内标题存在的数据
Page<StudentMaterialTemplate> page = new Page<StudentMaterialTemplate>(pageNo, pageSize);
String mainId = studentMaterialTemplate.getMainId();
String tableName = studentMaterialTemplate.getTableName();
String archiveCtgNoCode = studentMaterialTemplate.getArchiveCtgNoCode();
archiveCtgNoCode = archiveCtgNoCode.replace("*","%");
Map<String, String> query = new HashMap<>();//其它字段查询
Page<StudentMaterialTemplate> pageList = studentMaterialTemplateService.getStudentMaterialTemplate(page, archiveCtgNoCode, tableName, mainId,query);
return Result.OK(pageList);
}
实现类
package org.jeecg.modules.das.material.service.impl;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Param;
import org.jeecg.modules.das.material.entity.StudentMaterialTemplate;
import org.jeecg.modules.das.material.mapper.StudentMaterialTemplateMapper;
import org.jeecg.modules.das.material.service.IStudentMaterialTemplateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import java.util.List;
import java.util.Map;
/**
* @Description: student_material_template
* @Author: jeecg-boot
* @Date: 2024-06-11
* @Version: V1.0
*/
@Service
public class StudentMaterialTemplateServiceImpl extends ServiceImpl<StudentMaterialTemplateMapper, StudentMaterialTemplate> implements IStudentMaterialTemplateService {
@Autowired
private StudentMaterialTemplateMapper studentMaterialTemplateMapper;
public Page<StudentMaterialTemplate> getStudentMaterialTemplate(IPage<StudentMaterialTemplate> page,String archiveCtgNoCode, String tableName, String mainId,Map<String, String> query){
return studentMaterialTemplateMapper.getStudentMaterialTemplate(page,archiveCtgNoCode,tableName,mainId,query);
}
}
mapping类
package org.jeecg.modules.das.material.mapper;
import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Param;
import org.jeecg.modules.das.material.entity.StudentMaterialTemplate;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
/**
* @Description: student_material_template
* @Author: jeecg-boot
* @Date: 2024-06-11
* @Version: V1.0
*/
public interface StudentMaterialTemplateMapper extends BaseMapper<StudentMaterialTemplate> {
Page<StudentMaterialTemplate> getStudentMaterialTemplate(IPage<StudentMaterialTemplate> page,@Param("archiveCtgNoCode") String archiveCtgNoCode,@Param("tableName") String tableName, @Param("mainId") String mainId,@Param("query") Map<String, String> query);
}
xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.jeecg.modules.das.material.mapper.StudentMaterialTemplateMapper">
<select id="getStudentMaterialTemplate" parameterType="Object" resultType="org.jeecg.modules.das.material.entity.StudentMaterialTemplate">
SELECT
*
FROM
student_material_template
WHERE
archive_ctg_no_code LIKE #{archiveCtgNoCode}
AND maintitle NOT IN (
SELECT
maintitle
FROM
${tableName}
WHERE
pid = #{mainId})
<if test="query!= null">
<foreach collection="query.entrySet()" item="value" index="key" >
and ${key} = #{value}
</foreach>
</if>
</select>
</mapper>