问题场景
- 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内,变成了两条。