mybatis xml动态语句写法
2024-08-26 13:24:26
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>
最新文章
- Axure 资料搜集
- Ubuntu下忘记MySQL密码重设方法
- 子类重载父类的方法“parent::方法名”转于 恩聪PHP学习教程
- Jquery自定义扩展方法(二)--HTML日历控件
- RequestContextListener作用
- 关于listview的一些属性
- Highcharts选项配置详细说明文档(zz)
- sql server 跨库操作
- 解决rhel相关系统下yum找不到安装包的解决方法
- opencv保存选择图像中的区域
- LeetCode——Restore IP Addresses
- SearchBox( 搜索框) 组件
- ecshop代码详解之init.php
- getch()、getche()和getchar()函数
- 源码安装xadmin及使用
- C#委托、事件、线程
- Redis基础一(Linux)
- BZOJ2028: [SHOI2009]会场预约(set)
- Android--根据子控件的大小自动换行的ViewGroup
- chrome 开发并使用油猴 Tampermonkey 插件