mybatis异常:org.apache.ibatis.binding.BindingException: Parameter 'param' not found. Available param

org.apache.ibatis.binding.BindingException: Parameter 'param' not found. Available parameters are [param1, form]


原因:一般都是配置文件写错了,比如从Dao层传给Mapper层的参数是一个对象如下

	//根据条件查询hero
	public List<Hero> getHeroInformation(@Param("hero") Hero hero);

传到Mapper层的是一个对象而我Mapper.xml   where的写法错误示例如下

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.github.demo.dao.HeroMapper">
	<resultMap type="com.github.demo.vo.Hero" id="heroMapper">
		<id column="id" property="id" jdbcType="BIGINT" />
		<result column="hero_name" property="heroName" jdbcType="VARCHAR"/>
		<result column="hero_skills" property="heroSkills" jdbcType="VARCHAR"/>
		<result column="skill_plus_point" property="skillPlusPoint" jdbcType="VARCHAR"/>
		<result column="hero_out_of_the_pack" property="heroOutOfThePack" jdbcType="VARCHAR"/>
		<result column="hero_legend_story" property="heroLegendStory" jdbcType="VARCHAR"/>
		<result column="hero_orientation" property="heroOrientation" jdbcType="VARCHAR"/>
		<result column="hero_attribute" property="heroAttribute" jdbcType="VARCHAR"/>
   	</resultMap>
	
	<sql id="Hero_Base_Column_List">
		t.id,t.hero_name,t.hero_skills,t.skill_plus_point,t.hero_out_of_the_pack,t.hero_legend_story,t.hero_orientation,t.hero_attribute
	</sql>
	
	<select id="getHeroInformation" parameterType="com.github.demo.vo.Hero" resultMap="heroMapper">
		select 
		<include refid="Hero_Base_Column_List" />
		from mo_hero t where 1=1
					  <!-- 因为传进来的是对象所以这样写是取不到值得 -->
			<if test="heroOrientation!=null  and heroOrientation!=''">   and   t.hero_orientation = #{heroOrientation}  </if>
	    	<if test="heroAttribute!=null  and heroAttribute!=''">   and   t.hero_attribute = #{heroAttribute}  </if>
	</select>
	
</mapper>
正确的写法如下

注意要用对象。属性   取值

参看:
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值