参考下面文章,解释了一下@Param 注解的四种使用场
雁高飞:MyBatis 中 @Param 注解的四种使用场景,最后一种经常被人忽略!zhuanlan.zhihu.com![413b44c8e92269869d29fff9c14a1ca9.png](https://i-blog.csdnimg.cn/blog_migrate/07619d412c4f0f8168c436436e54798c.jpeg)
但是,在第四种情况下,竟然在不写这个注解情况下,有时候报错,有时候就没事~
报错信息如下:
org.apache.ibatis.binding.BindingException: Parameter 'XXX' not found. Available parameters arAvailable parameters are [arg1, arg0, param1, param2]] with root cause
原因是java8的一个特性。
参考如下
Java 8 Reflection Access to Parameter Names of Method and Constructor with Maven, Gradle and Eclipse using "-parameters" Compiler Argumentwww.concretepage.com![9be1535625484f3956927a7d86614ee7.png](https://i-blog.csdnimg.cn/blog_migrate/4131f9c428bda1b286c9957e2c9d800b.png)
对应:
eclipse:
![c090c8e593d73a7a67df144d4d8b370d.png](https://i-blog.csdnimg.cn/blog_migrate/0903a70cfb39bd15e2ad56f8ce057b02.png)
IDEA:
![2c5aeda17fd00bb7ce5115227a12ef4e.png](https://i-blog.csdnimg.cn/blog_migrate/55916554c8fcc5b15933d660e0da21ff.jpeg)
maven增加设定:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5</version>
<configuration>
<compilerArgs>
<arg>-parameters</arg>
</compilerArgs>
</configuration>
</plugin>
</plugins>
</build>