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>
==========================================================================================
我希望每一篇文章的背后,都能看到自己对于技术、对于生活的态度。
我相信乔布斯说的,只有那些疯狂到认为自己可以改变世界的人才能真正地改变世界。面对压力,我可以挑灯夜战、不眠不休;面对困难,我愿意迎难而上、永不退缩。
其实我想说的是,我只是一个程序员,这就是我现在纯粹人生的全部。
==========================================================================================