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. Mac下安装SecureCRT并激活

    今天花了好长的时间终于把SecureCRT安装成功了 现在分享给大家 安装的步骤, 希望对大家用帮助 Mac下的SecureCRT需要破解才能使用 所以有些费劲的.. 先下载SecureCRT和破解文 ...

  2. Unity3D判断当前所在平台

    Unity3D是一个跨平台的开发工具,支持的平台五花八门,常常开发一款游戏要发布到不同的平台,在不同的平台上会使用不同的代码,难道要我们各平台分别使用一套代码,单独编译一次吗?当然不用了,呵呵.    ...

  3. ok6410如何从sdram中启动uboot 调试 这是一个猜想还没有验证

    1\在smdk6410.h中定义宏 //#define CONFIG_SKIP_LOWLEVEL_INIT 1 //#define CONFIG_SKIP_RELOCATE_UBOOT 12\将编译的 ...

  4. golang 中strconv包用法

    链接:https://studygolang.com/articles/5003 http://www.cnblogs.com/golove/p/3262925.html

  5. 初试fiddler

    1.tools->Options->HTTPS勾:Decrypt HTTPS traffic //勾:Ignore server certificate errors(unsafe) // ...

  6. ORA-28002密码失效问题解决

    问题:提示ORA-28002解决: 第1种方法:数据库级别,需要重启查看过期时间: sql>SELECT * FROM dba_profiles WHERE profile='DEFAULT' ...

  7. orm 扩展

    """ORM小练习 如何在一个Python脚本或文件中 加载Django项目的配置和变量信息""" import os if __name_ ...

  8. Git操作手册(开发人员)

    一.git信息配置 1.1配置git账号信息 Window ->Preferences -> Team -> Git -> Configuration,在点击AddEntry… ...

  9. shell编程(五)之函数

    function:函数 函数只有被调用才会执行如何调用:给定函数名 函数名出现的地方,会被自动替换为函数代码 函数的生命周期:被调用时创建,返回时终止return命令返回自定义状态结果 0:成功 1- ...

  10. 解决 ImportError: No module named _internal

    参考: My pip is broken. _internal module cannot be imported. #5253 解决 ImportError: No module named _in ...