• mybatisplus多条件对象xml分页查询


    不要用它自带的

    selectPage方法,会有传参问题

    controller

    1. import java.util.Set;
    2. @RestController
    3. @RequiredArgsConstructor
    4. @RequestMapping("/deviceInfo" )
    5. public class DeviceInfoController {
    6. private final DeviceInfoService deviceInfoService;
    7. /**
    8. * 分页查询
    9. * @param page 分页对象
    10. * @param queryDto 设备信息查询对象
    11. * @return
    12. */
    13. @GetMapping("/page" )
    14. @PreAuthorize("@pms.hasPermission('proxy_deviceInfo_view')" )
    15. public R selectPage(Page page, @Validated(value = SelectVerify.class) DeviceInfoDTO queryDto) {
    16. return R.ok(deviceInfoService.selectForPage(page, queryDto));
    17. }
    18. }

    Mapper

    1. public interface DeviceInfoMapper extends BaseMapper {
    2. IPage selectForPage(Page page, @Param("queryDto") DeviceInfoDTO queryDto);
    3. List selectList(DeviceInfoDTO queryDto);
    4. }

    xml

    1. <resultMap id="deviceInfoVoMap" type="xx.xx.vo.DeviceInfoVO">
    2. <id property="id" column="id"/>
    3. <id property="groupId" column="group_id"/>
    4. <id property="deviceNumber" column="device_number"/>
    5. <id property="deviceCategory" column="device_category"/>
    6. <id property="deviceType" column="device_type"/>
    7. <id property="manufacturer" column="manufacturer"/>
    8. <id property="deviceModel" column="device_model"/>
    9. <id property="remark" column="remark"/>
    10. <id property="createBy" column="create_by"/>
    11. <id property="createTime" column="create_time"/>
    12. <id property="updateBy" column="update_by"/>
    13. <id property="updateTime" column="update_time"/>
    14. resultMap>
    15. <select id="selectForPage" resultMap="deviceInfoVoMap">
    16. SELECT
    17. di.*
    18. FROM device_info di
    19. <where>
    20. <if test="queryDto.groupId != null">
    21. AND di.group_id = #{queryDto.groupId}
    22. if>
    23. <if test="queryDto.deviceNumber != null and queryDto.deviceNumber != ''">
    24. AND di.device_number = #{queryDto.deviceNumber}
    25. if>
    26. <if test="queryDto.deviceTypeCollection != null and queryDto.deviceTypeCollection.size > 0">
    27. AND di.device_type IN
    28. <foreach collection="queryDto.deviceTypeCollection" index="idx" item="item" separator="," open="(" close=")">
    29. #{item}
    30. foreach>
    31. if>
    32. where>
    33. ORDER BY di.device_number ASC
    34. select>

    Server

    1. public interface DeviceInfoService extends IService {
    2. /**
    3. * 分页查询
    4. */
    5. IPage selectForPage(Page page, DeviceInfoDTO queryDto);
    6. }

    impl

    1. @Service
    2. @RequiredArgsConstructor
    3. public class DeviceInfoServiceImpl extends ServiceImpl implements DeviceInfoService {
    4. public IPage selectForPage(Page page, DeviceInfoDTO queryDto) {
    5. return baseMapper.selectForPage(page, queryDto);
    6. }
    7. }

  • 相关阅读:
    进销存管理的基本功能
    每日一题day15
    Go常用命令
    论文笔记:Evaluating the Performance of Large Language Models on GAOKAO Benchmark
    【数据结构】—— 树状数组
    xxl-job做集群的时候,用F5做负载均衡效率高还是直接写死几个服务器地址的效率高?
    【Java 进阶篇】JSP EL 详解
    基于java学生考勤管理系统设计——计算机毕业设计
    【Python高级语法】——迭代器 (Iterator)
    vue-mixin
  • 原文地址:https://blog.csdn.net/liuming690452074/article/details/139999908