MyBatis 一个比较奇怪的参数绑定问题
source link: https://www.v2ex.com/t/776265
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
众所周知如果 Mapper 需要多个参数时,需要在每个参数前加上 @ Param 注解,如:
User findByUserIdAndName(@Param("userId") Integer userId, @Param("name") String name);
但是我不加也可以,于是我没加,正常运行。 现在重构项目,拆分成父子项目,结果全部报错:org.apache.ibatis.binding.BindingException: Parameter 'xxx' not found. 网上都说是没加 @ Param 的原因,的确现在加上就不报错,但是为什么我之前没加也可以呢?
第 1 条附言 · 19 小时 14 分钟前
我懂了! 根据这里的回答 https://stackoverflow.com/a/49316086
To allow the input to be mapped to the operation method’s parameters, code implementing an endpoint should be compiled with -parameters. This will happen automatically if you are using Spring Boot’s Gradle plugin or if you are using Maven and spring-boot-starter-parent.
查看 spring-boot-starter-parent pom 文件,可以看到maven-compiler-plugin设置了 -parameters
所以 spring 项目编译时会自动加上 -parameters
但是,现在我重构了项目,删除了 spring-boot-starter-parent,把spring-boot-dependencies加入父项目的dependencyManagement,也就是
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<type>pom</type>
<version>2.4.5</version>
<scope>import</scope>
</dependency>
但是这家伙没有设置 -parameters,于是查询报错
Recommend
-
64
有问题,上知乎。知乎是中文互联网知名知识分享平台,以「知识连接一切」为愿景,致力于构建一个人人都可以便捷接入的知识分享网络,让人们便捷地与世界分享知识、经验和见解,发现更大的世界。
-
9
关于websocket跨域的一个奇怪问题 发表于...
-
6
V2EX › Python 一个特别奇怪的 pip 包依赖版本问题 dangyuluo · 19 小时 35 分钟前 · 398...
-
3
【DB系列】SpringBoot系列Mybatis之Mapper接口与Sql绑定几种姿势 ...
-
2
V2EX › 程序员 一个奇怪的 oracle 分页的问题 fdgdbr · 8 小时 39 分钟前 · 238 次点击
-
6
V2EX › 程序员 Windows 上的 Clion 遇到了一个奇怪的问题 zeal7s · 20 小时 26 分钟前 ·...
-
4
V2EX › 程序员 一个奇怪的压缩算法的问题 zzh1ad · 10 小时 23 分钟前 · 1427 次点...
-
8
V2EX › Python 遇到一个奇怪的问题,用 xpath 抓取这个网站 id 为'wc_channels'的 table 标签,会直接从 table 标签一直获取的 html 文件结尾
-
4
V2EX › 分享发现 QQ 邮箱竟然让我绑定手机号,有点奇怪
-
6
V2EX › 问与答 一个奇怪的网络问题, telnet 任意 IP + 端口都是通的
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK