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>
    
  • 相关阅读:
    ASP.NET HTTP模块和处理程序(5)(转载)
    充分利用ASP.NET的三种缓存提高站点性能(转载)
    LINQ体验(4)——LINQ简介和LINQ to SQL语句之Where
    理解DataSet的数据缓存机制
    在ASP.NET中实现AJAX(一)
    ASP.NET HTTP模块和处理程序(2)(转载)
    ASP.NET HTTP模块和处理程序(1)(转载)
    aspx页面中文汉字显示为乱码
    贫血还是充血?(转载)
    ASP.NET HTTP模块和处理程序(3)(转载)
  • 原文地址:https://www.cnblogs.com/jiqing9006/p/14447883.html
Copyright © 2011-2022 走看看