0
点赞
收藏
分享

微信扫一扫

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

yundejia 2024-07-01 阅读 25

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

mapper:

User findById(@Param("id") Long id);

xml:

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

2.解决:

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

    <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>

       

举报

相关推荐

0 条评论