SpringBoot整合Mybatis注解版---update时出现的问题

问题描述:

  1、sql建表语句

DROP TABLE IF EXISTS `department`;
CREATE TABLE `department` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`departmentName` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

  2、Repository层使用注解方式,

    语句如下:

@Update("UPDATE department SET departmentName=#{department.departmentName} WHERE id = #{id}")
public Integer updateEmp(Integer id, Department department); 

  显示错误信息:

org.apache.ibatis.binding.BindingException: Parameter 'department' not found. Available parameters are [arg1, arg0, param1, param2]
 由错误信息得知,参数发现不了,或者解析不了,可以用 arg1, arg0, param1, param2替换,假如我们不是用POJO对象Department进行传参,
而是使用单个字段分别进行传值,那么结果。
@Update("UPDATE department SET departmentName=#{param2} WHERE id = #{param1}")
public Integer updateEmp( Integer id, String departmentName);

  但是随着字段增多,我们使用POJO对象Department进行传参,需要在传过来的参数上添加注解,起别名的方式,获得参数,sql语句中通过对象名.属性名方式

获得参数的值,结果也是成功

 更改后得语句:
controller:
@PostMapping("/dept/{id}")
public Integer updateEmp(@PathVariable("id") Integer id,@Param("departmentName") Department department) {
return departmentService.updateEmp(id,departmentName);
}
-------------------------
service:
public Integer updateEmp(Integer id,Department department) {
Department dep = new Department(id,department);
return departmentMapper.updateEmp(id,dep);
}
-------------------------
repository:
@Mapper
public interface DepartmentMapper {
@Update("UPDATE department SET departmentName=#{department.departmentName} WHERE id = #{id}")
public Integer updateEmp(@Param("id") Integer id,@Param("department") Department department);
}

SpringBoot整合Mybatis注解版---update出现org.apache.ibatis.binding.BindingException: Parameter 'XXX' not found. Available parameters are [arg1, arg0, param1, param2]的更多相关文章

  1. org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.binding.BindingException: Parameter 'userId' not found. Available parameters are [arg1, arg0, param1, param2]

    2018-06-27 16:43:45.552  INFO 16932 --- [nio-8081-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : ...

  2. org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.binding.BindingException: Parameter 'username' not found. Available parameters are [1, 0, param1, param2]

    Spring+mybatis错误:org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.bi ...

  3. Mybatis报错 org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.binding.BindingException: Parameter 'parentCode' not found. Available parameters are [0, 1, param1, param2]

    orcal数据库使用mybatis接收参数,如果传的是多个参数,需要使用#{0},#{1},...等代替具体参数名,0 代表第一个参数,1 代表第二个参数,以此类推. 错误语句: <select ...

  4. org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.binding.BindingException: Parameter 'employeeId' not found. Available parameters are [page, map, param1, param2] 解决方法

    原因很简单就是没映射到接口添加 @Param 注解 ->@Param("map") 然后在mapper.xml map.employeeId 再次测试 已经解决 ->

  5. 怪事年年有,今天特别多!org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.binding.BindingException: Parameter 'empno' not found. Available parameters are [emp, deptno, param1, param

    错误: org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.binding.Binding ...

  6. 【Mybatis异常】 org.apache.ibatis.binding.BindingException: Parameter 'storeId' not found. Available parameters are [form, param1]

    一.异常信息 2019-05-31 16:06:25.272 [http-nio-10650-exec-3] WARN o.s.w.s.m.m.a.ExceptionHandlerExceptionR ...

  7. MyBatis报错 Parameter '0' not found. Available parameters are [arg1, arg0, param1, param2]

    修改 <update id="updateStatusById" parameterType="java.lang.Integer"> update ...

  8. Mybatis传多个参数的问题 及MyBatis报错 Parameter '0' not found. Available parameters are [arg1, arg0, param1 问题

    对于使用Mybatis ,传多个参数,我们可以使用对象封装外,还可以直接传递参数 对象的封装,例如查询对象条件basequery对象 <select id="getProductByP ...

  9. MyBatis 传List参数 nested exception is org.apache.ibatis.binding.BindingException: Parameter 'idList' not found.

    在MyBatis传入List参数时,MyBatis报错:nested exception is org.apache.ibatis.binding.BindingException: Paramete ...

随机推荐

  1. 大数开方 ACM-ICPC 2018 焦作赛区网络预赛 J. Participate in E-sports

    Jessie and Justin want to participate in e-sports. E-sports contain many games, but they don't know ...

  2. 博客系统(cnblog)

    1.用户表:Userinfo 2.博客站点表:Blog 3.标签表:Tag 4.分类表:Category 5.文章表:Article 6.点赞踩表:ArticelUpDown 7.评论表:Commen ...

  3. echart的x换行

    option = { legend: { y: 'bottom', data:['该业务正常类比例','该业务关注类比例','该业务不良类比例'] }, xAxis: { type: 'categor ...

  4. 解决pycharm左侧项目文件名中文字体乱码情况?中文显示口口口口.

    解决pycharm左侧项目文件名中文字体乱码情况?中文显示口口口口. 点击file,进入settings 出现 Appearance & Behavior 点击Appearance UI Op ...

  5. hdu2054 通过率低是有理由的

    这虽然是一道水题,但却巨坑,他题面上不说数据范围,也没有说数据类型,事实就是数据范围巨大,整型实型都有,所以必须用字符串去写,但是又涉及到小数,所以还要删除小数后面多余的0,比如1==1.0000,这 ...

  6. HL-D793G七位蓝色+PT6311驱动

    和之前那块一起买的.又画了这个屏幕驱动,还画了灯丝电源驱动,和以前画的stm8核心板在JLC拼板. 亚光黑颜色,不单独收钱! 切好水洗吹干! 忘记给排针加丝印,手写代之. 焊接的时候,脑子发热,以为把 ...

  7. redis缓存数据库

    redis 介绍 redis是业界主流的key-value nosql 数据库之一.和Memcached类似,它支持存储的value类型相对更多,包括string(字符串).list(链表).set( ...

  8. Elasticsearch-搭建自己的搜索系统

    参考链接: https://blog.csdn.net/weixin_42730079/article/details/81113806 https://www.cnblogs.com/dreamro ...

  9. linux准备工具VMware以及ubuntu

    链接:https://pan.baidu.com/s/1j7DZCmzOcC2rPAciHtZgkA 密码:et5s

  10. NBC朴素贝叶斯分类器 ————机器学习实战 python代码

    这里的p(y=1|x)计算基于朴素贝叶斯模型(周志华老师机器学习书上说的p(xi|y=1)=|Dc,xi|/|Dc|) 也可以基于文本分类的事件模型 见http://blog.csdn.net/app ...