关于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>
相关推荐
spencer_tseng16 小时前
‘<>‘ operator is not allowed for source level below 1.7
java
人道领域16 小时前
Day | 07 【苍穹外卖:菜品套餐的缓存】
java·开发语言·redis·缓存击穿·springcache
m0_7066532316 小时前
数据库与缓存操作策略:数据一致性与并发问题
java·数据库·缓存
独断万古他化16 小时前
【抽奖系统开发实战】Spring Boot 活动模块设计:事务保障、缓存优化与列表展示
java·spring boot·redis·后端·缓存·mvc
BioRunYiXue16 小时前
甘油不够了,能用植物油保存菌种吗?
java·linux·运维·服务器·网络·人工智能·eclipse
y = xⁿ16 小时前
【黑马点评二刷日记】分布式锁和Redisson
java·redis·分布式·缓存
空空kkk16 小时前
JVM面试知识点总结
java·jvm·面试
zdl68616 小时前
spring Profile
java·数据库·spring
m0_7066532316 小时前
数据倾斜全面解析与解决方案探析
java
程序员飞哥16 小时前
有个同事因为恐惧 AI 要离职了
java·后端·程序员