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. 详解UML中的6大关系(关联、依赖、聚合、组合、泛化、实现)

      UML中的6大关系相关英文及音标: 依赖关系 dependency --------> 关联关系 association ______> 聚合关系 aggregation ______ ...

  2. Android -- Glide框架详解(一)

    1,使用这个框架快两年了,今天去github上去看了一下,貌似已经从3.X升级到4.X了,想着自己还没有对这个框架在博客上做过总结,所以这里打算出三篇博客来介绍,内容有基本使用.3.X与4.X的不通. ...

  3. REST framework---基于类的视图

    一.程序设计 1.路由设计 from django.conf.urls import url from django.contrib import admin from app import view ...

  4. getparameter的使用

    在做项目的过程中,会遇到跳转的页面,直接打开到里面的子项,这个时候,看了UI给我设计了四个页面,如果做四个页面,肯定是可以实现的.但是这个不符合前端的设计.就在想通过点击传值进去,肯定是能够获取到的. ...

  5. javascript ----字符串的使用

    <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...

  6. JS对象格式化方法:pretty_format

    /* * 格式化 * */ var pretty_format = function (obj, indent) { if (obj === null) return 'null'; if (obj ...

  7. 使用pynlpir增强jieba分词的准确度

    在使用jieba分词时,发现分词准确度不高.特别是一些专业词汇,比如堡垒机,只能分出堡垒,并不能分出堡垒机.这样导致的问题是很多时候检索并不准确. 经过对比测试,发现nlpir进行分词效果更好.但是n ...

  8. js三种弹出框的用法

    https://blog.csdn.net/cui_angel/article/details/7784211 js中prompt()的用法

  9. 史上最全!Selenium元素定位的30种方式

    Selenium对网页的控制是基于各种前端元素的,在使用过程中,对于元素的定位是基础,只有准去抓取到对应元素才能进行后续的自动化控制,我在这里将对各种元素定位方式进行总结归纳一下. 这里将统一使用百度 ...

  10. 【做题】ZJOI2017仙人掌——组合计数

    原文链接 https://www.cnblogs.com/cly-none/p/ZJOI2017cactus.html 给出一个\(n\)个点\(m\)条边的无向连通图,求有多少种加边方案,使得加完后 ...