org.apache.ibatis.binding.BindingException: Parameter 'id' not found.Available parameters are [0, 1,
来源:互联网 发布:阿里云公网带宽费用 编辑:程序博客网 时间:2024/06/06 00:14
异常:
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.jadeon.mybatis.dao.DeptMapper">
<!--
namespace: 指定为实现类接口的全类名
deptno: 唯一标识
resultType: 返回值类型
#{id}: 从传递过来的参数中取deptno值
id: 接口的方法名
public Dept getById(Integer deptno);
databaseId: 所使用的数据库id
-->
<!-- public Dept getByIdAndDname(@Param("deptno")Integer deptno,@Param("dname")String dname); -->
<select id="getByIdAndDname" resultType="com.jadeon.mybatis.bean.Dept"
databaseId="oracle">
select * from dept where deptno = #{deptno}and dname=#{dname}
</select>
<select id="getById" resultType="com.jadeon.mybatis.bean.Dept"
databaseId="oracle">
select * from dept where deptno = #{id}
</select>
<select id="getById" resultType="com.jadeon.mybatis.bean.Dept"
databaseId="mysql">
select * from dept where deptno = #{id}
</select>
<!-- public void addDept(Dept dept);
mysql支持自增主键;自增主键的获取,mybatis也是利用statement.getGeneratedKeys()
要想前台获取添加的数字,添加两个属性
useGeneratedKeys="true": 使用自增主键获取主键值
keyProperty: 对应的主键属性,也就是mybatis获取到主键值以后,将这个值封装给javaBean的哪个属性
-->
<insert id="addDept" useGeneratedKeys="true" keyProperty="deptno" databaseId="mysql" >
insert into dept(dname,loc) values (#{dname},#{loc});
</insert>
<!--Oracle不支持 自增;Oracle使用序列序列来模拟自增;
每次插入的数据的主键是从序列中拿到的值:如歌获取到这个值?
-->
<insert id="addDept" databaseId="oracle" >
<!-- keyProperty:查出的主键封装给JavaBean的哪个属性
order="BEFORE":当前SQL在插入之前运行
AFTER:当前SQL在插入之后运行
resultType: 查出数据的返回值类型
BEFORE运行顺序:
先运行selectKey查询id的sql;查出id的值封装给javaBean的id属性
再运行插入的SQL;就可以取出id属性对应的值
AFTER:
先 运行插入的SQL(从序列中取出新值作为id)
再运行selectKey查询id的sql
-->
<selectKey keyProperty="deptno" order="BEFORE" resultType="Integer">
<!-- 编写查询主键的SQL语句 -->
<!-- BEFORE:-->
SELECT seq_deptno.nextval FROM dual
<!-- AFTER:
SELECT seq_deptno.currval FROM dual
-->
</selectKey>
<!-- 插入时的主键是从序列中拿到的 -->
<!-- BEFORE: -->
insert into dept(deptno,dname,loc)
values (#{deptno},#{dname},#{loc})
<!-- AFTER:
insert into dept(deptno,dname,loc)
values (seq_deptno.nextval,#{dname},#{loc})
-->
</insert>
<!-- public void updateDeptById(Dept dept); -->
<update id="updateDeptById">
update dept
set dname=#{dname},loc=#{loc}
where deptno=#{deptno}
</update>
<!-- public void deleteDeptById(Integer deptno); -->
<delete id="deleteDeptById">
delete from dept where deptno = #{deptno};
</delete>
</mapper>
org.apache.ibatis.binding.BindingException: Parameter 'id' not found. Available parameters are [0, 1, param1, param2]
解决办法:
命名参数:查看接口类的方法是否明确指定封装参数是map的key:@Param("deptno")Integer deptno
比如:
错误写法:
public Dept getByIdAndDname(Integer deptno,String dname);
正确写法:
public Dept getByIdAndDname(@Param("deptno")Integer deptno,@Param("dname")String dname);
或者在xml中列如:有背景色的字段中红色的字段——写成#{param1},#{param2}或者#{1},#{2}
<?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.jadeon.mybatis.dao.DeptMapper">
<!--
namespace: 指定为实现类接口的全类名
deptno: 唯一标识
resultType: 返回值类型
#{id}: 从传递过来的参数中取deptno值
id: 接口的方法名
public Dept getById(Integer deptno);
databaseId: 所使用的数据库id
-->
<!-- public Dept getByIdAndDname(@Param("deptno")Integer deptno,@Param("dname")String dname); -->
<select id="getByIdAndDname" resultType="com.jadeon.mybatis.bean.Dept"
databaseId="oracle">
select * from dept where deptno = #{deptno}and dname=#{dname}
</select>
<select id="getById" resultType="com.jadeon.mybatis.bean.Dept"
databaseId="oracle">
select * from dept where deptno = #{id}
</select>
<select id="getById" resultType="com.jadeon.mybatis.bean.Dept"
databaseId="mysql">
select * from dept where deptno = #{id}
</select>
<!-- public void addDept(Dept dept);
mysql支持自增主键;自增主键的获取,mybatis也是利用statement.getGeneratedKeys()
要想前台获取添加的数字,添加两个属性
useGeneratedKeys="true": 使用自增主键获取主键值
keyProperty: 对应的主键属性,也就是mybatis获取到主键值以后,将这个值封装给javaBean的哪个属性
-->
<insert id="addDept" useGeneratedKeys="true" keyProperty="deptno" databaseId="mysql" >
insert into dept(dname,loc) values (#{dname},#{loc});
</insert>
<!--Oracle不支持 自增;Oracle使用序列序列来模拟自增;
每次插入的数据的主键是从序列中拿到的值:如歌获取到这个值?
-->
<insert id="addDept" databaseId="oracle" >
<!-- keyProperty:查出的主键封装给JavaBean的哪个属性
order="BEFORE":当前SQL在插入之前运行
AFTER:当前SQL在插入之后运行
resultType: 查出数据的返回值类型
BEFORE运行顺序:
先运行selectKey查询id的sql;查出id的值封装给javaBean的id属性
再运行插入的SQL;就可以取出id属性对应的值
AFTER:
先 运行插入的SQL(从序列中取出新值作为id)
再运行selectKey查询id的sql
-->
<selectKey keyProperty="deptno" order="BEFORE" resultType="Integer">
<!-- 编写查询主键的SQL语句 -->
<!-- BEFORE:-->
SELECT seq_deptno.nextval FROM dual
<!-- AFTER:
SELECT seq_deptno.currval FROM dual
-->
</selectKey>
<!-- 插入时的主键是从序列中拿到的 -->
<!-- BEFORE: -->
insert into dept(deptno,dname,loc)
values (#{deptno},#{dname},#{loc})
<!-- AFTER:
insert into dept(deptno,dname,loc)
values (seq_deptno.nextval,#{dname},#{loc})
-->
</insert>
<!-- public void updateDeptById(Dept dept); -->
<update id="updateDeptById">
update dept
set dname=#{dname},loc=#{loc}
where deptno=#{deptno}
</update>
<!-- public void deleteDeptById(Integer deptno); -->
<delete id="deleteDeptById">
delete from dept where deptno = #{deptno};
</delete>
</mapper>
在mybatis中多个参数会被封装成一个map
key:使用@Param注释指定的值
value: 参数值
#{指定的key}取出对应的参数值
阅读全文
0 0
- org.apache.ibatis.binding.BindingException: Parameter 'id' not found.Available parameters are [0, 1,
- org.apache.ibatis.binding.BindingException: Parameter 'name' not found. Available parameters are [1,
- org.apache.ibatis.binding.BindingException: Parameter 'List' not found. Available parameters are [l
- ibatis.binding.BindingException: Parameter * not found. Available parameters [1, 0, param1, param2]
- org.apache.ibatis.binding.BindingException: Parameter 'receptionList' not found. Available parameter
- mybatis异常:org.apache.ibatis.binding.BindingException: Parameter 'param' not found. Available param
- mybatis异常:org.apache.ibatis.binding.BindingException: Parameter 'param' not found. Available param
- mybatis多参数查询问题:org.apache.ibatis.binding.BindingException: Parameter 'name' not found. Available par
- Caused by: org.apache.ibatis.binding.BindingException: Parameter 'offset' not found. Available param
- Caused by: org.apache.ibatis.binding.BindingException: Parameter 'stuId' not found. Available parame
- mybatis多参数查询问题:org.apache.ibatis.binding.BindingException: Parameter 'name' not found. Available par
- org.apache.ibatis.binding.BindingException: Parameter 'set' not found
- org.apache.ibatis.binding.BindingException: Parameter '__frch_org_0' not found
- SSM报错Caused by: org.apache.ibatis.binding.BindingException: Parameter 'id' not found
- mybatis问题org.apache.ibatis.binding.BindingException: Parameter 'title' not found.
- mybatis问题org.apache.ibatis.binding.BindingException: Parameter 'param' not found.
- mybaits异常:org.apache.ibatis.binding.BindingException: Parameter 'date' not found.
- mybatis问题org.apache.ibatis.binding.BindingException: Parameter 'title' not found.
- JAVA:2006年培养学员8万人,每年增长25%,请问按照次增长速度,到哪一年培养学员人数将达到20万人?while do while for语句
- windows下配置python环境
- C++11 override 保留字作用
- 跟着安全牛大表哥学渗透
- Javascript中使用a元素解析url
- org.apache.ibatis.binding.BindingException: Parameter 'id' not found.Available parameters are [0, 1,
- linux中几个文本文件查看命令
- WebStorm for mac 破解
- Shader语法高亮代码补全Visual Studio插件
- Java ActiveMQ 队列模式
- 使用Ideal创建javaWeb项目
- linux中系统文件的管理
- swoole中的worker_id,task_id以及多个server是否会有影响
- 小猪的猪栏文章类目导航