zoukankan      html  css  js  c++  java
  • mybatis xml动态语句写法

    mapper.java:

     /**
        * @Description: 根据摄像机Id查询出入记录
        * @Param:
         * name        姓名
         * monitorId   布控ID
         * starttime   开始时间
         * endtime     结束时间
         * begin       页码
         * pageSize    查询数量
        * @return:
        * @throws Exception
        * @author: hw
        * @date: 2019/6/11 14:28
        */
        List<OutInRecords> queryOutInRecords(@Param("name") String name,@Param("monitorId") String monitorId,
                                             @Param("starttime") String starttime, @Param("endtime") String endtime,
                                             @Param("begin") Integer begin, @Param("pageSize") Integer pageSize);
    

    mapper.xml

    <select id="queryOutInRecords" resultMap="OutInRecords" parameterType="map">
        select
        a_oir.similarity,a_oir.`status`,a_oir.`timestamp`,a_ci.in_out,a_mi.monitor_name,a_si.person_type,a_si.address,a_si.`name`
        from aiapp_out_in_record a_oir
        LEFT JOIN aiapp_camera_info a_ci ON a_ci.camera_id = a_oir.camera_id
        LEFT JOIN aiapp_staff_info a_si ON a_oir.faceimage_id = a_si.faceimage_id
    
        <if test="monitorId != null ">
          LEFT JOIN aiapp_monitor_info a_mi ON a_mi.monitor_id = ${monitorId}
        </if>
        <if test="monitorId == null ">
          LEFT JOIN aiapp_monitor_info a_mi ON a_mi.monitor_id = (SELECT a_cm.monitor_id FROM aiapp_camera_monitor a_cm WHERE a_cm.camera_id = a_oir.camera_id)
        </if>
    
        <trim prefix="where" prefixOverrides="and">
          <if test="monitorId != null ">
            AND a_oir.camera_id in (SELECT a_cm.camera_id FROM aiapp_camera_monitor a_cm WHERE a_cm.monitor_id = ${monitorId})
          </if>
    
          <if test="name != null ">
            AND a_oir.faceimage_id = (SELECT a_si.faceimage_id FROM aiapp_staff_info a_si WHERE a_si.`name` = '${name}')
          </if>
    
          <if test="starttime != null and endtime != null">
            AND a_oir.`timestamp` BETWEEN ${starttime} and ${endtime}
          </if>
          <if test="starttime != null and endtime == null">
            AND a_oir.`timestamp` > ${starttime}
          </if>
          <if test="starttime == null and endtime != null">
            AND ${starttime} > a_oir.`timestamp`
          </if>
        </trim>
    
        order by a_oir.`timestamp` desc
        <if test="begin != null and pageSize != null">
          limit ${begin}, ${pageSize}
        </if>
      </select>
    

      

    ========================================================================================== 我希望每一篇文章的背后,都能看到自己对于技术、对于生活的态度。 我相信乔布斯说的,只有那些疯狂到认为自己可以改变世界的人才能真正地改变世界。面对压力,我可以挑灯夜战、不眠不休;面对困难,我愿意迎难而上、永不退缩。 其实我想说的是,我只是一个程序员,这就是我现在纯粹人生的全部。 ==========================================================================================
  • 相关阅读:
    .NET下的多线程编程—1线程机制概述
    C#温故而知新学习系列之面向对象编程—定义类与创建类的对象(一)
    C#温故而知新学习系列之面向对象编程—方法(四)
    C#温故而知新学习系列之XML编程—XmlSerializer类把复杂对象序列化为XML文档(六)
    深度剖析ASP.NET架构—ASP.NET请求的处理过程(一)
    ref参数
    Android实现开机自动运行程序(转)
    ASP.NET中的状态—基于服务器端的状态管理Session(二)
    深度剖析ASP.NET架构—HttpHandler(三)
    .NET下的多线程编程—2前台线程和后台线程
  • 原文地址:https://www.cnblogs.com/weihuang6620/p/11005563.html
Copyright © 2011-2022 走看看