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>
正确的写法如下
注意要用对象。属性 取值
参看: