Mybatis-plus 查询返回对象内有List<String>属性

业务逻辑
查询用户数据时携带用户所管理小区的名称List< String >
用户与管理的小区是一对多的关系

查询返回实体类

@Data
public class UserVo{

    private Long userId;

    private String loginName;

    private String userName;

    private String password;

    private Integer userTypeEnum;

    private String email;

    private String phone;

    private Integer sexEnum;

    private String avatar;

    private Integer statusEnum;

    private Integer deleteFlag;

    private String loginIp;

    private LocalDateTime loginDate;

    private Long companyId;

    private String companyName;

    private String remark;

    /**
     *     根据小区id查询
     */
    private Long estateId;

    private List<String> estateNameList;

mapper.xml

<resultMap id="BaseResultMap" type="com.yiju.modules.system.user.pojo.entity.UserVo">
        <collection property="estateNameList" ofType="java.lang.String" javaType="java.util.List" select="getEstateName" column="user_id">
            <result column="estateNameList"/>
        </collection>
    </resultMap>


    <select id="userVoList" resultMap="BaseResultMap">
        SELECT
            distinct(t1.user_id) userId,
            t1.*,
            t2.company_name
        FROM
	        sys_user t1
	    LEFT JOIN charge_company t2 ON t1.company_id = t2.company_id
	    left join charge_user_estate t3 on t1.user_id=t3.user_id
	    </select>

    <select id="getEstateName" parameterType="java.lang.Long" resultType="java.lang.String" >
        select t4.house_estate_name estateNameList
        from charge_user_estate t3
	    inner join charge_base_estate t4 on t3.estate_id=t4.house_estate_id
	    where t3.user_id=#{user_id}
    </select>

mapper.java

public interface UserMapper extends BaseMapper<User> {

    List<UserVo> userVoList();

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值