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. 自主设计BootLoader框架笔记一栏

  2. python模块之psutil

    一.模块安装 1.简介 psutil是一个跨平台库(http://pythonhosted.org/psutil/)能够轻松实现获取系统运行的进程和系统利用率(包括CPU.内存.磁盘.网络等)信息. ...

  3. andriod studio连接SQLite

    SQLite SQLite是一种嵌入式的数据库引擎,以文件的形式保存数据的,专门适用于资源有限的设备上进行适量的数据存储. 从本质上来看,SQLite的操作方式只是一种更为便捷的文件操作,当应用程序创 ...

  4. mysql使用replace和on duplicate key update区别

    实际业务使用中,有时候会遇到插入数据库,但是如果某个属性(比如:主键)存在,就做更新.通常有两种方式:1.replace into  2.on duplicate key update 但是在使用过程 ...

  5. Anaconda3自带jupyter

    1.cmd命令行中输入 JupyterNotebook 2.系统自动调起下面页面(注册端口冲突是打不开的)

  6. 像母语者一样说美语 How to Improve Spoken American English - Sound like a Native Speaker

    视频讲解: 视频详情见:https://www.bilibili.com/video/av75075387/ 总结分析: 001 要点总结: 1. 本富兰克林方法: 要你写下一切听到的东西 2. 辅音 ...

  7. 范仁义html+css课程---2、html常用标签

    范仁义html+css课程---2.html常用标签 一.总结 一句话总结: html常用的标签有 标题标签.div.span.p.hr.br标签 等 1.html中的标题标签有哪些? <h1& ...

  8. Shell脚本——make命令和Makefile文件【转】

    https://blog.csdn.net/twc829/article/details/72729799 make命令是一个常用的编译命令,尤其在C/C++开发中,make命令通过makefile文 ...

  9. 关于如何重写Controller和Service技术攻关文档

    版权声明:本文为博主原创文章,遵循CC 4.0 by-sa版权协议,转载请附上原文出处链接和本声明. 本文链接:https://blog.csdn.net/weixin_39784756/articl ...

  10. 微信小程序wx.uploadFile的两个坑

    -- setImage:function(e){ var _this = this //坑1 wx.chooseImage({ count: , sizeType: ['original', 'com ...