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. Error:java: Annotation processing is not supported for module cycles. Please ensure that all modules from cycle [web_dao,web_service] are excluded from annotation processing

    早上学习maven环境搭建时遇到的这个问题 下面这个错误的大概意思是:模块之间的互相依赖 Error:java: Annotation processing is not supported for ...

  2. NOIP2018总结

    细细想来,学习OI也有4年多的时间了,今年已经是第二次参加noip提高组了,有必要写点什么了 NOIP2018 记得在天刚蒙蒙亮的时候走进70中,这是第四次了,但紧张只增不减,在刺骨的寒风下身体微微发 ...

  3. 【转】数据处理常用的sql语句整理

    一下语句都是基于 mysql数据库 查询是否使用索引 explain  select * FROM t_table1; 结果列的含义: table:此次查询操作是关联哪张数据表 type:连接查询操作 ...

  4. Visual Studio Git本地Repos和GitHub远程Repos互操作

    近期准备将一个项目开源到GitHub中,N-Sharding,.Net版本的分库分表数据访问框架.中间遇到了点小问题,整理了一下. 1. GitHub上Create New Repos 2. 代码Ch ...

  5. oracle数据库开启与关闭

    先用CRT软件链接-——建立会话——telent/ssh——写服务器Ip——点击链接——输入密码  # su - oracle   打开数据库 # cmd   进入特权模式 $ sqlplus / a ...

  6. Liunx网络技术管理及进程管理

    Linux网络技术管理及进程管理(week2_day4)   OSI七层模型和TCP/IP四层模型 OSI七层模型:OSI(Open System Interconnection)开放系统互连参考模型 ...

  7. 《视觉SLAM十四讲课后作业》第二讲

    1.设线性⽅程 Ax = b,在 A 为⽅阵的前提下,请回答以下问题:1. 在什么条件下,x 有解且唯⼀? 非齐次线性方程在A的秩与[A|B]的秩相同时方程有解,当R(A)=R(A,B)=n时方程有唯 ...

  8. php 把数组保存为标准的数组格式,存储到文件中

    <?php $file='./test.php'; $array=array('color'=> array('blue','red','green'),'size'=> array ...

  9. 在vim下打开终端

    注意:仅在vim8.1下可用 使用方法: :term 打开默认的终端 如果是linux,或者使用wsl, :term bash Ctrl+W/Ctrl+N 将终端设置成normal模式

  10. opencv学习之路(35)、SURF特征点提取与匹配(三)

    一.简介 二.opencv中的SURF算法接口 三.特征点匹配方法 四.代码 1.特征点提取 #include "opencv2/opencv.hpp" #include < ...