mybatis异常:org.apache.ibatis.binding.BindingException: Parameter 'param' not found. Available param
2016-04-22 17:54
896 查看
org.apache.ibatis.binding.BindingException: Parameter 'param' not found. Available parameters are [param1, form]
原因:一般都是配置文件写错了,比如从Dao层传给Mapper层的参数是一个对象如下
传到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>正确的写法如下
注意要用对象。属性 取值
参看:
http://mybatis-user.963551.n3.nabble.com/Parameters-in-resultType-map-td4026012.html
原因:一般都是配置文件写错了,比如从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>正确的写法如下
注意要用对象。属性 取值
参看:
http://mybatis-user.963551.n3.nabble.com/Parameters-in-resultType-map-td4026012.html
相关文章推荐
- Ruby中的异常处理代码编写示例
- MySQL抛出Incorrect string value异常分析
- 浅谈C#中简单的异常引发与处理操作
- 详解C#编程中异常的创建和引发以及异常处理
- 详解JavaScript中的异常处理方法
- java程序中的延时加载异常及解决方案
- 解析Java异常的栈轨迹及其相关方法
- 深入浅析mybatis oracle BLOB类型字段保存与读取
- MyBatis MapperProvider MessageFormat拼接批量SQL语句执行报错的原因分析及解决办法
- .NET(C#):Emit创建异常处理的方法
- windows7服务器上weblogic启动失败异常解决方法
- 有关ajax的error与后台的异常问题解决
- 深入探讨JAVA中的异常与错误处理
- GO语言异常处理机制panic和recover分析
- oracle+mybatis 使用动态Sql当插入字段不确定的情况下实现批量insert
- MyBatis学习笔记(二)之关联关系
- 浅谈JAVA 异常对于性能的影响
- 浅析Mybatis 在CS程序中的应用
- Java Mybatis框架入门基础教程
- Windows下Java+MyBatis框架+MySQL的开发环境搭建教程