zoukankan      html  css  js  c++  java
  • 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>
    
  • 相关阅读:
    如何确定Kafka的分区数、key和consumer线程数
    Storm程序永久代内存溢出
    JVM堆内存相关的启动参数:年轻代、老年代和永久代的内存分配
    Git添加本地项目出现fatal: unable to get credential storage lock: File exists
    Kafka的通讯协议
    文件上传 数据对比
    jquery 弹出层
    XSS 简单理解之:AntiSamy
    XSS 简单理解
    超人说我最叼蝙蝠侠笑了 超级英雄战力排名
  • 原文地址:https://www.cnblogs.com/jiqing9006/p/14447883.html
Copyright © 2011-2022 走看看