mybatis異常:org.apache.ibatis.binding.BindingException: Parameter 'param' not found. Available param
阿新 • • 發佈:2019-02-16
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>
注意要用物件。屬性 取值