我因例外而失去理智,我需要您的帮助。
我已将查询写入映射器,该映射器根据以下两个条件从表中检索记录:列表中的“位置”和另一个条件中的“技能”。
因此,基本上,如果用户选择了多个技能来查找,则查询将恢复所有具有这些技能的记录...
这么简单却又如此令人困惑,因为我正在使用两个foreach ...一个有效,而另一个无效...
这是查询:
<select id="selectAllByFilter" resultMap="BaseResultMap">
select distinct
<include refid="Base_Column_List" /><include refid="Join_Column_List" />
from "ANAG_REQS" A JOIN "ANAG_REQS_RISORSE" R ON A."ID_REQS_RDA"=R."ID_REQS" LEFT JOIN "SEC_USER" U ON R."ID_USER"=U."ID"
LEFT JOIN "USER_LOCATION" S ON S."ID_REQS_USER"= R."ID_REQS"
LEFT JOIN "USER_SKILL" RS ON RS."ID_REQS_USER"= R."ID_REQS"
LEFT JOIN "USER_CUSTOMER" RC ON RC."ID_REQS"= R."ID_REQS"
WHERE 1=1
<if test="filter.idREQS != null">
AND A."ID_REQS_RDA" = #{filter.idREQS,jdbcType=INTEGER}
</if>
<if test="filter.states != null and filter.states.size()>0 and not statesuspended">
AND A."state_RDA" IN
<foreach item="item" collection="filter.states" index="index"
open="(" separator="," close=")">
#{item}
</foreach>
AND R."state" != 'suspended'
</if>
<if test="filter.states != null and filter.states.size()>0 and statesuspended">
AND (A."state_RDA" IN
<foreach item="item" collection="filter.states" index="index"
open="(" separator="," close=")">
#{item}
</foreach>
OR A."state_RDA" = 'published' AND R."state" = 'suspended')
</if>
<if test="filter.states.isEmpty() and statesuspended">
AND A."state_RDA" = 'published' AND R."state" = 'suspended'
</if>
<if test="filter.dataREQSDa != null">
AND A."DATA_REQS_RDA" >= #{filter.dataREQSDa,jdbcType=DATE}
</if>
<if test="filter.dataREQSA != null">
AND A."DATA_REQS_RDA" <= #{filter.dataREQSA,jdbcType=DATE}
</if>
<if test="filter.pm != null and filter.pm != ''">
<bind name="pattern1" value="'%' + filter.pm + '%'" />
AND lower(U."USER_NAME") LIKE lower(#{pattern1})
</if>
<if test="filter.CUSTOMER != null">
AND RC."ID_CUSTOMER" = #{filter.CUSTOMER,jdbcType=INTEGER}
</if>
<if test="filter.locationselected != null and filter.locationselected.size()>0">
AND S."ID_LOCATION" IN
<foreach item="item" collection="filter.locationselected" index="index"
open="(" separator="," close=")">
#{item}
</foreach>
</if>
<if test="filter.skills != null and filter.skills.size()>0">
AND RS."ID_SKILL" IN
<foreach item="item" collection="filter.skills" index="index"
open="(" separator="," close=")">
#{item}
</foreach>
</if>
</select>
最新的foreach(filter.skills)上引发了异常。
问题在于先前的foreach(filter.locationSelected)就像一个超级按钮一样工作。唯一的区别是技能是整数列表,而locationSelected是字符串列表。但这不是原因,因为我什至尝试使用String列表,但问题仍然存在...
RS.ID_SKILL是一个int4,因此,只要我的逻辑正常(如果我不发疯),我基本上是在检查int是否在整数列表中。 ..
但是仍然有BadSQLGrammarException声明:运算符不存在:整数=可变字符提示:没有运算符匹配给定的名称和参数类型。您可能需要添加显式类型转换。
我在做什么错?!
救救我!
编辑:S.“ ID_LOCATION”相反是varchar,因此我正在检查其内容是否在字符串列表中...基于此,唯一的逻辑结论是mybatis'foreach不能使用整数列表.....我不知道.....
答案 0 :(得分:3)
您是否尝试通过以下方式修改查询: 更换
AND RS."ID_SKILL" IN
作者
AND cast(RS."ID_SKILL" as character varying) IN