出现错误的动态sql
<select id="taskList" resultMap="TssTaskResult">
<include refid="selectTssTaskVo"/>
<where>
<if test="task.name != null and task.name != ''">and name like concat('%', #{task.name}, '%')</if>
<if test="task.type != null and task.type != ''">and type = #{task.type}</if>
and project_id = #{task.projectId}
</where>
</select>
需要说明的是:属性type是属于枚举类型,因此我们在使用mybatis的if判断中,不能将其当作字符串来进行处理。这也是以上语句报错的症结所在:task.type != ‘’,既然是枚举对象,那直接判断是否为空即可。
修改后
<select id="taskList" resultMap="TssTaskResult">
<include refid="selectTssTaskVo"/>
<where>
<if test="task.name != null and task.name != ''">and name like concat('%', #{task.name}, '%')</if>
<if test="task.type != null">and type = #{task.type}</if>
and project_id = #{task.projectId}
</where>
</select>