mybatis {arg0} 与 {0}
解决方案:
MyBatis的XML的配置文件中声明设置属性的useActualParamName参数值为假
<setting name="useActualParamName" value="false" />
代码展示:
Dao层函数
User getUserBys(int id,String name);
对应的mapping.xml
<select id="getUserBys" resultType="model.User">
select * from user where id = #{0} and name=#{1}
</select>
这种方法应该是对的,但是如果你使用的是mybatis3.4.2或者之后的版本,就会产生绑定异常:
org.apache.ibatis.binding.BindingException: Parameter '0' not found. Available parameters are [arg1, arg0, param1, param2]
从异常可以看出在没有使用@参数注解的情况下,传递参数需要使用
#{}为arg0 - #{} ARGN#或者{}参数1 - #{} paramn
- 更换下mapping.xml中的代码
<select id="getUserBys" resultType="model.User">
select * from user where id = #{arg0} and name=#{arg1}
</select>
此时代码就会正常运行
下面贴上3.4.1以及之前版本的绑定异常信息:
org.apache.ibatis.binding.BindingException: Parameter 'arg0' not found. Available parameters are [0, 1, param1, param2]
可以发现3.4.1版本中传递参数可以使用#{0} - #{N}
问题原因
MyBatis的通过XMLConfigBuilder类来加载配置文件中的各项参数
- 3.4.2版本之前设置属性中useActualParamName参数的默认值为flase
XMLConfigBuilder.class的settingsElement方法中的源代码
configuration.setUseActualParamName(booleanValueOf(props.getProperty("useActualParamName"), true));
- 3.4.2版本之后设置属性中useActualParamName参数的默认值为true
XMLConfigBuilder.class的settingsElement方法中的源代码
configuration.setUseActualParamName(booleanValueOf(props.getProperty("useActualParamName"), false));
mybatis {arg0} 与 {0}的更多相关文章
- mybatis plus3.1.0 热加载mapper
今天又开始写业务代码了,每次修改SQL都要重启服务,实在是浪费时间. 想起之前研究过的<mybatis plus3.1.0 热加载mapper>,一直没有成功,今天静下心来分析了问题,终于 ...
- springboot项目war包部署及出现的问题Failed to bind properties under 'mybatis.configuration.mapped-statements[0].
1.修改pom文件 修改打包方式 为war: 添加tomcat使用范围,provided的意思即在发布的时候有外部提供,内置的tomcat就不会打包进去 <groupId>com.scho ...
- spring整合mybatis,springMVC的0配置文件方式
0配置文件的形式主要是采用spring3.0提供的@configuration注解和spring容器在启动的时候会加载实现了WebApplicationInitializer的类,并调用其onStar ...
- mybatis将传入0识别成空字符串
mybatis将传入的Integer类型的0被识别成空字符串,网上的解决办法: <if test="status != null and status != '' or status ...
- SpringBoot整合MyBatis与MySql8.0
一.前言 之前已经有一篇文章讨论过SpringBoot整合MyBatis,因而此篇不在重复累赘,本文主要是最新版的SpringBoot2.0与MyBatis.最新MySQL8.0整合过程中遇到的问题进 ...
- Mybatis 3.3.0 Log4j配置
最近做一个SSM学习项目,配置log4j,mybatis用下面的方式配置,不管用,打印不出执行的SQL语句. log4j.logger.java.sql.Connection=DEBUGlog4j.l ...
- mybatis理解(0)
- 问题-MyBatis不识别Integer值为0的数据
问题-MyBatis不识别Integer值为0的数据 问题:使用MyBatis的过程中,发现一个值为0的数据,Mybatis所识别,最后定位才发现,是自己的写法有问题, <if test=&qu ...
- Spring3.0 与 MyBatis框架 整合小实例
本文将在Eclipse开发环境下,采用Spring MVC + Spring + MyBatis + Maven + Log4J 框架搭建一个Java web 项目. 1. 环境准备: 1.1 创建数 ...
随机推荐
- python web自动化测试中失败截图方法汇总
在使用web自动化测试中,用例失败则自动截图的网上也有,但实际能落地的却没看到,现总结在在实际应用中失败截图的几种方法: 一.使用unittest框架截图方法: 1.在tearDown中写入截图的 ...
- YAML入门
概要 YAML(是YAML Ain't Markup Language的缩写,尾音的发音类似Camel)是一种序列化数据的语言(类似json, xml),使用轻量高可读性的语法描述list, dict ...
- day_11py学习
''' 字典增加和删除 1.添加 xxx[新的key] = value 2.删除 del xxx[key] 3.修改 xxx[已存在的key] = new_value 4.查询 xxx.get(key ...
- ASP.NET Core 的Windows和IIS宿主(自动翻译记录)
https://docs.microsoft.com/en-us/aspnet/core/publishing/iis?tabs=aspnetcore2x 支持的操作系统 以下操作系统的支持: Win ...
- POJ 1456 - Supermarket - [贪心+小顶堆]
题目链接:http://poj.org/problem?id=1456 Time Limit: 2000MS Memory Limit: 65536K Description A supermarke ...
- iOS 模拟器运行不能联网 PAC Fetch failed with error
app在模拟器是哪个启动成功会自动连接服务器,然后Xcode控制台报错, 模拟器 PAC Fetch failed with error [NSURLErrorDomain:-1001] 这类问题有好 ...
- Uniform Resource Name Server
HTTP The Definitive Guide 按址标识 identify by address 按名标识 identify by name Domain Name Server Uniform ...
- Mac 下的 C++ 开发环境
1. Xcode 创建 C++ 项目 Xcode (版本 4.6.3)默认支持创建 C++ 项目,步骤很简单:打开 Xcode,新建一个项目:在 OS X 中的 Application 中选择 Com ...
- take a cpu core offline
[root@vrouter1 ~]# cat /sys/devices/system/cpu/online -,,- [root@vrouter1 ~]# cat /sys/devices/syste ...
- [web][nginx] 初识nginx -- 使用nginx搭建https DPI解码测试环境
环境 CentOS 7 X86 文档: https://nginx.org/en/docs/ 安装: [root@dpdk ~]# cat /etc/yum.repos.d/nginx.repo [n ...