关于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>
相关推荐
可乐ea5 小时前
【Spring Boot + MyBatis|第7篇】JWT 登录认证与拦截器实现
java·spring boot·后端·mybatis·状态模式
步步为营DotNet5 小时前
借助 C# 14 特性强化 .NET 后端数据验证的深度实践
java·c#·.net
西安邮电大学5 小时前
有关栈的经典算法题
java·后端·其他·算法·面试
手握风云-5 小时前
ProtoBuf:从序列化原理到高性能架构底座(一)
java·网络·架构
摇滚侠5 小时前
SpringMVC 入门到实战 配置类替换 XML 配置文件 86-91
xml·java·后端·spring·maven·intellij-idea
栗子~~5 小时前
金融场景下BigDecimal 运算规范 + 常用场景使用 + 数据库字段设计详解
java·数据库·金融
我登哥MVP5 小时前
SpringCloud Alibaba 核心组件解析:服务注册与发现(Nacos)
java·spring boot·后端·spring·spring cloud·java-ee·maven
兰令水5 小时前
leecodecode【单调栈】【2026.6.12打卡-java版本】
java·开发语言·算法
云烟成雨TD6 小时前
Agent Scope Java 2.x 系列【8】工具调用
java·人工智能·agent
AI人工智能+电脑小能手6 小时前
【大白话说Java面试题 第112题】【并发篇】第12题:AQS 中节点的入队时机有哪些?
java·开发语言·面试