关于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>
相关推荐
今天和Aboo结婚了吗13 分钟前
【Broker一重启消息没了:一次RabbitMQ非持久化+没开Confirm的血亏事故】
java·rabbitmq·messagequeue·bug排查
daidaidaiyu6 小时前
一文学习 工作流开发 BPMN、 Flowable
java
SuniaWang7 小时前
《Spring AI + 大模型全栈实战》学习手册系列 · 专题六:《Vue3 前端开发实战:打造企业级 RAG 问答界面》
java·前端·人工智能·spring boot·后端·spring·架构
sheji34167 小时前
【开题答辩全过程】以 基于springboot的扶贫系统为例,包含答辩的问题和答案
java·spring boot·后端
m0_726965988 小时前
面面面,面面(1)
java·开发语言
xuhaoyu_cpp_java8 小时前
过滤器与监听器学习
java·经验分享·笔记·学习
程序员小假9 小时前
我们来说一下 b+ 树与 b 树的区别
java·后端
Meepo_haha9 小时前
Spring Boot 条件注解:@ConditionalOnProperty 完全解析
java·spring boot·后端
sheji34169 小时前
【开题答辩全过程】以 基于springboot的房屋租赁系统的设计与实现为例,包含答辩的问题和答案
java·spring boot·后端