首页 新闻 会员 周边

org.apache.ibatis.exceptions.PersistenceException:

0
悬赏园豆:30 [已解决问题] 解决于 2019-08-27 17:58

org.apache.ibatis.exceptions.PersistenceException:

Error updating database. Cause: org.apache.ibatis.binding.BindingException: Parameter 'id' not found. Available parameters are [0, 1, param1, param2]

The error may involve com.demo3.dao.Student3Dao.save-Inline

The error occurred while setting parameters

SQL: insert into student3 values (?,?,?,?,?)

Cause:org.apache.ibatis.binding.BindingException: Parameter 'id' not found. Available parameters are [0, 1, param1, param2]

这是翻译过的错误
org.apache.ibatis.binding.BindingException: Parameter 'id' not found. Available parameters are [0, 1, param1, param2]
org.apache.ibatis.exceptions.PersistenceException:
更新数据库出错。原因:org.apache.ibatis.binding。BindingException:没有找到参数“id”。可用参数为[0,1,param1, param2]
错误可能涉及com.demo3.dao.Student3Dao.save-Inline
设置参数时发生错误

SQL:插入到student3值中(?,?,?,?,?)

# #原因:org.apache.ibatis.binding。BindingException:没有找到参数“id”。可用参数为[0,1,param1, param2]

mapper.xml

<mapper namespace="com.demo3.dao.Student3Dao">
<insert id="save" parameterType="com.demo3.bean.Student3">
insert into student3 values (#{id},#{name},#{age},#{gender},#{birthday})
</insert>
<select id="getAll" resultMap="student3">
select * from student3
</select>
<resultMap type="com.demo3.bean.Student3" id="student3">
<result column="sname" property="name"/>
<result column="sage" property="age"/>
<result column="sgender" property="gender"/>
</resultMap>
</mapper>

这是练飞mybatis动态代理的时候出的错,前面demo1、demo2没有便用动态理时一切正常,demo3查询OK更新数据库异常找不到参数id.
求各位大神找下出错点和解决方案!

一世红尘的主页 一世红尘 | 菜鸟二级 | 园豆:321
提问于:2019-08-03 11:05
< >
分享
最佳答案
0

动态代理不需要再手动添加SqlSession 对象
将Student3Dao中的save(SqlSession sqlSession,Student3 stu)
改为save(Student3 stu)即可

一世红尘 | 菜鸟二级 |园豆:321 | 2019-08-03 22:51
其他回答(1)
0

<resultMap type="com.demo3.bean.Student3" id="student3">
<result column="sname" property="name"/>
<result column="sage" property="age"/>
<result column="sgender" property="gender"/>
</resultMap>

可能出错的地方--> 结果集中并没有指定主键字段!!!
尝试添加一下如下的, 或许能解决你的问题
<id column="表的主键字段,或者可以为查询语句中的别名字段" jdbcType="字段类型" property="映射pojo对象的主键属性" />

收获园豆:30
三生_93 | 园豆:232 (菜鸟二级) | 2019-08-03 19:05

表的id 与实体类id相同不用写

支持(0) 反对(0) 一世红尘 | 园豆:321 (菜鸟二级) | 2019-08-03 22:35
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册