Mybaitis之Could not find SQL statement ...Base_Column_LIst'

本文详细解析了在使用Mybatis框架时遇到的SQL包含异常问题,通过具体案例分析,指出错误信息“找不到要与refid一起包含的SQL语句”可能的原因及解决方案,包括检查ID拼写、代码段位置和大小写敏感性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

首先抛出异常如下

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奇奇怪怪的问题

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值