mapper层 @Param("startDate") String startDate@Param表示xml里输入的值
如下代表startDate
<selectid="queryByCondition"resultMap="map">
select
<includerefid="Base_Column "/>
from eb_pm_cont where 1=1
<iftest="state != null and state != ''">
contract_state = #{state}
</if>
<iftest="num != null and num != ''">
and num = #{num}
</if>
<iftest="startDate != null and startDate != ''">
AND time > CONCAT(#{startDate},' 00:00:00')
</if>
<iftest="endDate !=null and endDate != ''">
AND time < CONCAT(#{endDate},' 23:59:59')
</if>
</select>
开始结束可如上处理>和<
where 1=1 是为了避免where 关键字后面的第一个词直接就是 “and”而导致语法错误。
CONCAT(#{endDate},' 23:59:59')记住要带空格
拼接字符串,输入为String即可。不同角色,应该加入角色查询