关于mybatis中Mapper对应xml要写参数名的

  1. 问题: 当我们在Mapper和xml之中传递参数时,必须要用@Param注解来标识参数名, 否则参数就对应不上, 但每个参数都写@Param就很烦人, 情况如下:

mapper:

java 复制代码
User findById(@Param("id") Long id);

xml:

XML 复制代码
    <select id="findById" resultType="com.hz.domain.User">
        select * 
        from user 
        where id = #{id}
    </select>

2.解决:

在pom文件中, 加入maven编译插件,配置-parameters即可, 如下

XML 复制代码
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.0</version>
                <configuration>
                    <skip>true</skip>
                    <compilerArgs>
                        <arg>-parameters</arg>
                    </compilerArgs>
                </configuration>
            </plugin>
        </plugins>
    </build>
相关推荐
怒放吧德德3 小时前
Spring Boot 实战:RSA+AES 接口全链路加解密(防篡改 / 防重放)
java·spring boot·后端
郑州光合科技余经理6 小时前
代码展示:PHP搭建海外版外卖系统源码解析
java·开发语言·前端·后端·系统架构·uni-app·php
大大水瓶7 小时前
Tomcat
java·tomcat
dustcell.7 小时前
haproxy七层代理
java·开发语言·前端
游离态指针7 小时前
以为发消息=下单成功?RabbitMQ从0到秒杀实战的完整踩坑笔记
java
BD_Marathon7 小时前
工厂方法模式
android·java·工厂方法模式
玹外之音8 小时前
Spring AI MCP 无状态服务器实战:构建AI智能用户管理系统
java·后端
java干货8 小时前
Redis 的 ZipList 是什么?它是怎么解决内存碎片问题的?
java
失重外太空啦8 小时前
Tomcat
java·服务器·tomcat
屎到临头想搅便8 小时前
TOMCAT
java·tomcat