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字段获取参数值。
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/134789.html