public interface DeviceFileInfoVOMapper { List<QueryFileDTO> selectVideoByField(String devId, Long chl, Date startTime, Date endTime, Pagination pagination); }
<select id="selectVideoByField" resultMap="videoFileMap"> SELECT file_id FROM t_device_file_info WHERE 1=1 <trim> <if test="devId != null"> AND dev_id=#{devId,jdbcType=VARCHAR} </if> <if test="chl != null"> AND chl=#{chl,jdbcType=BIGINT} </if> <if test="startTime != null"> AND start_time >= #{startTime,jdbcType=TIMESTAMP} </if> <if test="endTime != null"> AND end_time <= #{endTime,jdbcType=TIMESTAMP} </if> </trim> </select>
在 Mapper 中定義的方法參數添加 @Param 註解,@Param 註解的值和xml中引用的參數名一致便可。app
@Param("devId"),則在xml中使用 #{devId}ide
public interface DeviceFileInfoVOMapper { List<QueryFileDTO> selectVideoByField(@Param("devId") String devId, @Param("chl") Long chl, @Param("startTime") Date startTime, @Param("endTime") Date endTime, Pagination pagination); }