java中sql映射机制

@Setter
@Getter
public class CustomerPagePojo {
    private Integer id;
    private String name;
    private String phone;
    private int auth;
    private String idcard;
    @ApiModelProperty("是否老年人默认值0非 1是")
    private Integer old;
    @ApiModelProperty("是否危险,默认值0非 1是")
    private Integer danger;
    // 自动注解数据
    @ApiModelProperty("社区id")
    private Integer communityId;
    @ApiModelProperty("社区名称")
    private String communityName;
    @ApiModelProperty("小区标志")
    private Integer villageId;
    @ApiModelProperty("小区名称")
    private String villageName;
    private Integer age;
    private Integer sex;
    private int buildingId;
    private String buildingName;
    private int floorId;
    private String floorName;
    private int houseId;
    private String houseName;
}

这是一个数据库不存在的表数据。
是多个表数据结合在一起的数据。
java中提供了一种映射机制,通过sql语句来自动映射。

<select id="pageCondition" resultType="com.smart.model.user.pojo.CustomerPagePojo">
    SELECT a.id,a.`name`, a.phone ,a.idcard,a.age,a.sex,a.old,a.danger,a.auth,b.community_id ,
    b.village_id,c.`name` community_name,d.`name` village_name,
    e.id as buildingId,
    e.descreption building_name,
    f.id as floorId,
    f.alias floor_name,
    g.id as houseId,
    g.description house_name
    from user_customer a
    LEFT JOIN user_customer_village b on a.id=b.customer_id
    LEFT JOIN community c on c.id=b.community_id
    LEFT JOIN village d on d.id=b.village_id
    LEFT JOIN building e on b.building_id=e.id
    LEFT JOIN floor f on b.floor_id=f.id
    LEFT JOIN house g on b.house_id=g.id
    where 1=1
    and a.identity !='WORKER'
    <if test="minAge!=null">
        and age &gt; #{minAge,jdbcType=INTEGER}
    </if>
    <if test="maxAge!=null">
        and age &lt; #{maxAge,jdbcType=INTEGER}
    </if>
    <if test="phone!=null">
        and a.phone = #{phone,jdbcType=VARCHAR}
    </if>
    <if test="name!=null">
        and a.`name` like concat('%',#{name,jdbcType=VARCHAR},'%')
    </if>
    <if test="communityId!=null">
        and b.community_id=#{communityId,jdbcType=INTEGER}
    </if>
    <if test="villageId!=null">
        and b.village_id=#{villageId,jdbcType=INTEGER}
    </if>
    <!--        GROUP BY a.id,b.community_id-->
    order by a.id desc
    <if test="pageable!=null">
        limit
        #{pageable.index,jdbcType=BIGINT},
        #{pageable.length,jdbcType=BIGINT}
    </if>
</select>
posted @ 2021-02-25 16:52  TBHacker  阅读(173)  评论(0编辑  收藏  举报