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>
    
  • 相关阅读:
    java拦截器与过滤器打印请求url与参数
    mybatis学习笔记(六)使用generator生成mybatis基础配置代码和目录结构
    【IDEA】IDEA创建Maven的Web项目并运行以及打包
    【环境变量】Linux 下三种方式设置环境变量与获取环境变量
    【Git】GitHub的SSH提交配置[
    spring配置redis注解缓存
    【查看linux配置】查看linux系统常用的命令,Linux查看系统配置常用命令
    Redis集群
    linux中wget 、apt-get、yum rpm区别
    spring+redis的集成,redis做缓存
  • 原文地址:https://www.cnblogs.com/jiqing9006/p/14447883.html
Copyright © 2011-2022 走看看