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>

  

mybatis xml动态语句写法的更多相关文章

  1. Mybatis xml mapper 特殊写法总结

    项目告一段落,业务代码也写得差不多了,框架仍然用的是 ssm ,为了省去单表数据库操作的代码编写,继续用 mybatis generator 生成单表对应的实体类.dao层映射关联及配置文件,私下还尝 ...

  2. 分享知识-快乐自己:Mybatis 基础动态语句

    目录: User: package mlq.bean; /** * 用户实体类 */ public class User { private Integer uId; private String u ...

  3. (转)mybatis:动态SQL

    概述:在mybatis中,动态语句是个非常强大和灵活的功能,并且动态语句可以放在sql的任何地方,利用该功能,我们可以写出非常灵活的代码.在mybatis的动态语句中常常可能会用到以下几个运算和逻辑判 ...

  4. mybatis where in语句中参数过多

    ps : mybatis在in中参数过多 出现问题 com.microsoft.sqlserver.jdbc.SQLServerException: 传入的请求具有过多的参数.该服务器支持最多 210 ...

  5. myBatis动态语句详解

    SQL 映射XML 文件是所有sql语句放置的地方.需要定义一个workspace,一般定义为对应的接口类的路径.写好SQL语句映射文件后,需要在MyBAtis配置文件mappers标签中引用,例如: ...

  6. mybatis中的.xml文件总结——mybatis的动态sql

    resultMap resultType可以指定pojo将查询结果映射为pojo,但需要pojo的属性名和sql查询的列名一致方可映射成功. 如果sql查询字段名和pojo的属性名不一致,可以通过re ...

  7. Mybatis 删除多条数据XML SQL语句删除

    Mybatis 删除多条数据XML SQL语句删除 1.删除多条数据SQL写法 <delete id="deleteParamsByIds"> delete from ...

  8. MyBatis 最强大的特性之一就是它的动态语句功能

    MyBatis 最强大的特性之一就是它的动态语句功能.如果您以前有使用JDBC或者类似框架的经历,您就会明白把SQL语句条件连接在一起是多么的痛苦,要确保不能忘记空格或者不要在columns列后面省略 ...

  9. Mybatis中动态SQL语句中的parameterType不同数据类型的用法

    Mybatis中动态SQL语句中的parameterType不同数据类型的用法1. 简单数据类型,    此时#{id,jdbcType=INTEGER}中id可以取任意名字如#{a,jdbcType ...

随机推荐

  1. 交互设计算法基础(1) - Binary Search

    int binary_search(int[] list, int item) { int low = 0; int high = list.length-1; while (low <= hi ...

  2. vim的四大模式

    vim的四大模式 总结了下我经常使用的模式中的一些基本命令 正常模式 通过vim进入到界面, 首次即为正常模式 编辑模式 (i,a,o,s,I,A,S) i: 当前节点插入光标点 a: 下一个字母后插 ...

  3. fgets()函数

    声明: char *fgets(char *str,int n,FILE* stream) 参数: str—这是指向一个字符数组的指针,该数组存储了要读取的字符串 n – 这是要读取的最大字符数(包括 ...

  4. 数据结构实验之查找二:平衡二叉树 (SDUT 3374)

    #include <stdio.h> #include <string.h> #include <stdlib.h> struct node { int data; ...

  5. CF891C Envy(离线/在线+可撤销并查集/并查集/LCT)

    前置知识 最小生成树及证明 做法 每个不同权值没影响,仅需判断该次询问每种权值是否在"小于该权值的所有边加完"之后,可以全部加进来 离线:询问的所有边全堆到一起,按权值排序,然后同 ...

  6. avalon结合原生js tab切换

    <div class="fishqc-tap"> <div ms-class="[@codePic!=''&&@codeInfo!='' ...

  7. Communications link failure due to underlying exception: ** BEGIN NESTED EXC

    一是将 wait_timeout=31536000 interactive_timeout=31536000 将过期时间修改为1年. 二是在连接URL上添加参数:&autoReconnect= ...

  8. 000 装docker

    直接参考别人的文章,经过验证,没有问题,需要网络. URL: https://www.cnblogs.com/qgc1995/archive/2018/08/29/9553572.html 我是虚拟机 ...

  9. Nginx 配置操作注意事项

    Nginx reload 会中断现有连接吗? - 知乎https://www.zhihu.com/question/57096250 在NGINX上配置HTTPS---血的教训--要重启NGINX - ...

  10. PHP技术知识点整理

    1.解释mvc (1)mvc即 模型model,视图view,控制器controller:是一种模型,是一种编程思想,就是把一个应用的输入.输出.数据处理分开,分解耦合(2)A..视图,数据采集和处理 ...