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.pluginsgroupId>
- <artifactId>maven-compiler-pluginartifactId>
- <version>3.8.0version>
- <configuration>
- <skip>trueskip>
- <compilerArgs>
- <arg>-parametersarg>
- compilerArgs>
- configuration>
- plugin>
- plugins>
- build>