关于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>
相关推荐
Via_Neo2 小时前
JAVA中以2为底的对数表示方式
java·开发语言
野生技术架构师3 小时前
一线大厂Java面试八股文全栈通关手册(含源码级详解)
java·开发语言·面试
廋到被风吹走3 小时前
【AI】Codex 多语言实测:Python/Java/JS/SQL 效果横评
java·人工智能·python
tERS ERTS3 小时前
MySQL中查看表结构
java
坊钰3 小时前
Java 死锁问题及其解决方案
java·开发语言·数据库
于先生吖3 小时前
SpringBoot+MQTT 无人健身房智能管控系统源码实战
java·spring boot·后端
仍然.4 小时前
算法题目---模拟
java·javascript·算法
wefly20174 小时前
纯前端架构深度解析:jsontop.cn,JSON 格式化与全栈开发效率平台
java·前端·python·架构·正则表达式·json·php
nbwenren5 小时前
node.js内置模块之---crypto 模块
java
weyyhdke6 小时前
springboot和springframework版本依赖关系
java·spring boot·后端