首先抛出异常如下:
org.apache.ibatis.builder.IncompleteElementException: Could not find SQL statement to include with refid 'com.example.demo.Mapper.TargetDimensionMapper.Base_Column_LIst'
at org.apache.ibatis.builder.xml.XMLIncludeTransformer.findSqlFragment(XMLIncludeTransformer.java:99)
at org.apache.ibatis.builder.xml.XMLIncludeTransformer.applyIncludes(XMLIncludeTransformer.java:61)
at org.apache.ibatis.builder.xml.XMLIncludeTransformer.applyIncludes(XMLIncludeTransformer.java:83)
at org.apache.ibatis.builder.xml.XMLIncludeTransformer.applyIncludes(XMLIncludeTransformer.java:51)
at org.apache.ibatis.builder.xml.XMLStatementBuilder.parseStatementNode(XMLStatementBuilder.java:88)
at org.apache.ibatis.session.Configuration.lambda$buildAllStatements$2(Configuration.java:787)
at java.util.Collection.removeIf(Unknown Source)
at org.apache.ibatis.session.Configuration.buildAllStatements(Configuration.java:786)
at org.apache.ibatis.session.Configuration.hasStatement(Configuration.java:763)
at org.apache.ibatis.session.Configuration.hasStatement(Configuration.java:758)
at org.apache.ibatis.binding.MapperMethod$SqlCommand.resolveMappedStatement(MapperMethod.java:254)
at org.apache.ibatis.binding.MapperMethod$SqlCommand.<init>(MapperMethod.java:224)
at org.apache.ibatis.binding.MapperMethod.<init>(MapperMethod.java:50)
at org.apache.ibatis.binding.MapperProxy.lambda$cachedMapperMethod$0(MapperProxy.java:62)
at java.util.concurrent.ConcurrentHashMap.computeIfAbsent(Unknown Source)
at org.apache.ibatis.binding.MapperProxy.cachedMapperMethod(MapperProxy.java:62)
at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:57)
at com.sun.proxy.$Proxy64.selectAllDimension(Unknown Source)
at com.example.demo.service.impl.Dimension_Service.selectallDemention(Dimension_Service.java:75)
at com.example.demo.Controller.TargetDimension_Controller.SelectAlldimension(TargetDimension_Controller.java:76)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:189)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:138)
......(后面不贴了,太长了)
什么意思呢?“找不到要与refid一起包含的SQL语句”,先检查一下自己的Mapper.xml映射文件。
自己再网上查找后说有两个原因:
1.确实没有id为“xxx”的sql代码段
1.1 标签名写错
1.2 id名写错了
2. 确实有id为“xxx”的sql代码段
可能是代码段放置的位置有问题,被引用代码段应该放在引用的代码片段之前,原因是Mybatis用的是sax解析。
到这里基本上可以解决大多数人的问题了,然而我的问题还没结束
好了,检查了一下我自己的:
<sql id="Base_Column_List">
DIMENSION_ID, DIMENSION_CODE, DIMENSION_NAME, DIMEMSION_GROUP, DIMENSION_DESCRIBE,DIMENSION_STATE, UPDATE_LAST, UPDATE_TIME
</sql>
下面的使用:
<select id="selectAllDimension" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from target_dimension_table
</select>
好像没什么问题,别的地方也没有弄错,怎么回事呢,又看了一眼报错:
Could not find .......Base_Column_LIst'
nnd,我没又用到这个玩意好吧?我的是“Base_Column_List”,List! List!好吧好吧,你这样我就把上面那个改成大写,
<sql id="Base_Column_LIst">
DIMENSION_ID, DIMENSION_CODE, DIMENSION_NAME, DIMEMSION_GROUP, DIMENSION_DESCRIBE,DIMENSION_STATE, UPDATE_LAST, UPDATE_TIME
</sql>
这总可以了吧,结果。。。。。。。。。。。。。。。。。。。。。。。
Could not find SQL statement to include with refid 'com.example.demo.Mapper.TargetDimensionMapper.Base_Column_List'
??????
无FUCK可说,简单粗暴,两个都加上!!!
运行,postman访问,出结果:
好吧,完成,Mybatis奇奇怪怪的问题