SpringBoot报错:Parameter ‘pkId‘ not found. Available parameters are [map, param1]
SpringBoot中,使用mybatis框架进行自定义SQL查询时候,报错:org.mybatis.spring.MyBatisSystemException:nested exception is org.apache.ibatis.binding.BindingException:Parameter 'pkId' not found. Available parameters are [ma
·
SpringBoot中,使用mybatis框架进行自定义SQL查询时候,报错:
org.mybatis.spring.MyBatisSystemException:
nested exception is org.apache.ibatis.binding.BindingException:
Parameter 'pkId' not found. Available parameters are [map, param1]
mapper接口类代码如下:
public interface TestMapper extends BaseMapper<Test> {
List<Test> selectAllByCondition(@Param("map") Map<String, Object> map);
}
xml映射文件中定义如下:
<select id="selectAllByCondition" parameterType="java.util.Map" resultType="com.gitee.demo.domain.Test">
select
<include refid="sqlFields"/>
from test
<where>
<if test="pkId != null and pkId != ''">
AND pk_id = #{pkId}
</if>
<if test="custName != null and custName != ''">
AND cust_name = #{custName}
</if>
</where>
</select>
报错原因:
xml映射文件中,字段没有通过map参数获取。
xml映射文件,正确的写法如下:
<select id="selectAllByCondition" parameterType="java.util.Map" resultType="com.gitee.demo.domain.Test">
select
<include refid="sqlFields"/>
from test
<where>
<if test="map.pkId != null and map.pkId != ''">
AND pk_id = #{map.pkId}
</if>
<if test="map.custName != null and map.custName != ''">
AND cust_name = #{map.custName}
</if>
</where>
</select>
使用map.xxx字段获取参数值。
更多推荐
已为社区贡献2条内容
所有评论(0)