mybatis分页,pageSize设置10,返回2条。bug记录。

问题场景

  • mybatis分页插件PageHelper
  • 实体类
@Data
public class UserListDTO {

   private String userName;
   private  String mobile;

   private List<String> storeNameDelivery;

   private String companyCode;
   private String companyName;

   private String userType;

   private String userStatus;

   private String userShutUp;

   private  Integer userId;

}
  • xml代码
<resultMap id="userListDTO" type="com.mg.lifemg.vr.pojo.base.dto.UserListDTO">
        <id column="userId" jdbcType="INTEGER" property="userId"/>
        <result column="user_name" jdbcType="VARCHAR" property="userName"/>
        <result column="mobile" jdbcType="VARCHAR" property="mobile"/>
        <result column="company_code" jdbcType="INTEGER" property="companyCode"/>
        <result column="company_name" jdbcType="VARCHAR" property="companyName"/>
        <result column="user_type" jdbcType="VARCHAR" property="userType"/>
        <result column="user_status" jdbcType="VARCHAR" property="userStatus"/>
        <result column="user_shut_up" jdbcType="TIMESTAMP" property="userShutUp"/>
        <collection property="storeNameDelivery" ofType="java.lang.String">
            <result column="store_name_delivery"/>
        </collection>
    </resultMap>
    <sql id="list_user_dot">
	u.nickname AS user_name,
	u.mobile,
	CONCAT(
	concat_ws("(",
	concat_ws( ")--",
	concat_ws( "(", s.`store_name`, s.shop_code ), cdm.deliver_name ), cdm.deliver_code),")") AS store_name_delivery,
	bc.code as company_code,
	u.type as user_type,
	u.status as user_status,
	u.shut_up as user_shut_up
    </sql>
    <select id="selectByQo" resultMap="userListDTO">
    SELECT
        <include refid="list_user_dot"/>
    FROM
	`user` AS u
	JOIN user_store AS us ON u.id = us.user_id
	JOIN store AS s ON s.id = us.store_id
	JOIN company_deliver_map AS cdm ON cdm.deliver_code = s.deliver_code
	JOIN branch_company AS bc ON u.branch_company = bc.id

	<where>
	<if test="qo.userName != null and qo.userName != ''">and u.nickname like Concat('%', #{qo.userName},'%') </if>
	<if test="qo.mobile != null and qo.mobile != ''">and u.mobile = #{qo.mobile} </if>
	<if test="qo.storeName != null and qo.storeName != ''">and s.store_name like Concat('%', #{qo.storeName})</if>
	<if test="qo.companyId != null and qo.companyId != ''">and u.branch_company = #{qo.companyId}</if>
	<if test="qo.deliveryCode != null and qo.deliveryCode != ''">and s.deliver_code = #{qo.deliveryCode}</if>
	<if test="qo.userType != null and qo.userType != ''">and u.`type` = #{qo.userType}</if>
	<if test="qo.userStatus != null and qo.userStatus != ''">and u.status = #{qo.userStatus}</if>
	<if test="qo.userShutUp != null and qo.userShutUp != ''">and u.shut_up = #{qo.userShutUp}</if>
    </where>
    </select>

原因分析

因为,对象中有一个list,mybatis把查出来的十条数据,聚合到list内,变成了两条。

解决办法,不用标签聚合,多一次查询实现。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值