基本概念
RowBoundsPlugin:通过ResultSet的游标实现的分页查询插件,容易出现性能问题
<plugin type="org.mybatis.generator.plugins.RowBoundsPlugin">
问题描述
Caused by: java.lang.IllegalArgumentException: Mapped Statements collection already contains value for club.zstuca.platform.mapper.UserMapper.selectByExampleWithRowbounds. please check file [E:\Code\Project\JAVA\platform\target\classes\mapper\UserMapper.xml] and file [E:\Code\Project\JAVA\platform\target\classes\mapper\UserMapper.xml]
at org.apache.ibatis.session.Configuration$StrictMap.put(Configuration.java:947) ~[mybatis-3.5.3.jar:3.5.3]
at org.apache.ibatis.session.Configuration$StrictMap.put(Configuration.java:903) ~[mybatis-3.5.3.jar:3.5.3]
at org.apache.ibatis.session.Configuration.addMappedStatement(Configuration.java:702) ~[mybatis-3.5.3.jar:3.5.3]
at org.apache.ibatis.builder.MapperBuilderAssistant.addMappedStatement(MapperBuilderAssistant.java:297) ~[mybatis-3.5.3.jar:3.5.3]
at org.apache.ibatis.builder.xml.XMLStatementBuilder.parseStatementNode(XMLStatementBuilder.java:113) ~[mybatis-3.5.3.jar:3.5.3]
at org.apache.ibatis.builder.xml.XMLMapperBuilder.buildStatementFromContext(XMLMapperBuilder.java:137) ~[mybatis-3.5.3.jar:3.5.3]
at org.apache.ibatis.builder.xml.XMLMapperBuilder.buildStatementFromContext(XMLMapperBuilder.java:130) ~[mybatis-3.5.3.jar:3.5.3]
at org.apache.ibatis.builder.xml.XMLMapperBuilder.configurationElement(XMLMapperBuilder.java:120) ~[mybatis-3.5.3.jar:3.5.3]
... 77 common frames omitted
Process finished with exit code 0
问题分析
RowBoundsPlugin生成的代码存在两个id为selectByExampleWithRowbounds的方法导致[Mapped Statements collection already contains value]错误。
<select id="selectByExampleWithRowbounds" parameterType="club.zstuca.platform.model.UserExample" resultMap="BaseResultMap">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
This element was generated on Tue Feb 04 21:26:31 CST 2020.
-->
select
<if test="distinct">
distinct
</if>
<include refid="Base_Column_List" />
from user
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
<if test="orderByClause != null">
order by ${orderByClause}
</if>
</select>
<select id="selectByExampleWithRowbounds" parameterType="club.zstuca.platform.model.UserExample" resultMap="BaseResultMap">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
This element was generated on Tue Feb 04 21:26:31 CST 2020.
-->
select
<if test="distinct">
distinct
</if>
<include refid="Base_Column_List" />
from user
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
<if test="orderByClause != null">
order by ${orderByClause}
</if>
</select>
但是为什么会多一个,暂时未知,可能是个BUG。
解决方案
删除其中一个即可。
参考文章
Mybatis Generator 相关:
https://www.cnblogs.com/yejg1212/p/9592369.html
Mapped Statements collection already contains value 相关:
https://www.iteye.com/blog/dugu61888-2202549
http://www.zuidaima.com/blog/4316526703807488.htm
https://www.cnblogs.com/yanan7890/p/9474336.html
https://www.cnblogs.com/scode2/p/8744710.html
Spring Boot配置[mybatis.type-aliases-package] 相关:
https://blog.csdn.net/daijiguo/article/details/82827430
https://www.cnblogs.com/yejg1212/p/9592369.html
Mybatis的generator生成XXXWithBLOBS.java文件 相关:
https://blog.csdn.net/sinat_31350717/article/details/80574105
https://blog.csdn.net/qq_34982426/article/details/83180450
STZG 发布了1371 篇原创文章 · 获赞 237 · 访问量 33万+ 关注