mybatis include动态传递参数,在include里面判断传递参数
废话不多说,上代码
错误代码
<if test="param.queryType != null and param.queryInfo != null">
AND imp_crm_opportunity.pk_crm_opportunity IN
<include refid="opportunityQuery">
<property name="queryType" value="${param.queryType}"/>
<property name="queryInfo" value="'${param.queryInfo}'"/>
</include>
</if>
queryType字段属性为Integer
queryInfo字段为String
sql片段
<sql id="opportunityQuery">
(
SELECT
DISTINCT
val
FROM
v_imp_crm_synthesize_query
WHERE
indexClomn like CONCAT('%', ${queryInfo}, '%')
<if test="queryType != 0">
AND dataType = ${queryType}
</if>
)
</sql>
错误原因,mybatis接口扫描不到传递的queryType对象参数
正确写法
sql片段
<sql id="opportunityQuery">
(
SELECT
DISTINCT
val
FROM
v_imp_crm_synthesize_query
WHERE
indexClomn like CONCAT('%', #{queryInfo}, '%')
<if test="param.queryType != 0">
AND dataType = ${queryType}
</if>
)
</sql>