gpt4 book ai didi

java - 生成文件中的 MyBatis 异常

转载 作者:行者123 更新时间:2023-12-02 08:21:20 25 4
gpt4 key购买 nike

我使用 MyBatis Generator 1.3.1 创建了一个 Mapper.xml 文件。 MyBatis解析Mapper文件时,会抛出BuilderException:

Exception in thread "main" org.apache.ibatis.builder.BuilderException: Unknown element <#comment> in SQL statement.
at org.apache.ibatis.builder.xml.XMLStatementBuilder.parseDynamicTags(XMLStatementBuilder.java:83)
at org.apache.ibatis.builder.xml.XMLStatementBuilder.parseStatementNode(XMLStatementBuilder.java:43)
at org.apache.ibatis.session.Configuration.parseStatementNodes(Configuration.java:513)
at org.apache.ibatis.session.Configuration.buildStatementsForNamespace(Configuration.java:502)
at org.apache.ibatis.session.Configuration.buildStatementsFromId(Configuration.java:467)
at org.apache.ibatis.session.Configuration.getMappedStatement(Configuration.java:391)
at org.apache.ibatis.binding.MapperMethod.setupCommandType(MapperMethod.java:160)
at org.apache.ibatis.binding.MapperMethod.<init>(MapperMethod.java:48)
at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:37)
at $Proxy1.selectByExample(Unknown Source)

parseDynamicTags 无法识别 <#comment> 字段。它正在解析的 XML 部分是 selectByExample:

  <select id="selectByExample" resultMap="BaseResultMap" parameterType="test.model.TblPosStageExample" >
<!-- WARNING - @mbggenerated .. -->
select
<if test="distinct" >
distinct
</if>
<include refid="Base_Column_List" />
from tbl_Pos_Stage
<if test="_parameter != null" >
<include refid="Example_Where_Clause" />
</if>
<if test="orderByClause != null" >
order by ${orderByClause}
</if>
</select>

MyBatis 似乎已经解析了第一条注释和 select 语句。它刚刚解析了 #text 类型的节点,但我不确定 #comment 来自哪里。

我没有修改生成的文件,我很困惑它过去运行正常,但突然停止了。

<小时/>

编辑:Base_column_list

  <sql id="Base_Column_List" >
<!--
WARNING - @mbggenerated
This element is automatically generated by MyBatis Generator, do not modify.
This element was generated on Wed Mar 23 08:04:42 EST 2011.
-->
SurrogatePK, businessDate, positionId, busAIdCode, {95 columns deleted for brevity}
marketValueCcy, settledMarketValueCcy
</sql>

这是 example_where_clause

<sql id="Example_Where_Clause" >
<!--
WARNING - @mbggenerated
This element is automatically generated by MyBatis Generator, do not modify.
This element was generated on Wed Mar 23 08:04:42 EST 2011.
-->
<where >
<foreach collection="oredCriteria" item="criteria" separator="or" >
<if test="criteria.valid" >
<trim prefix="(" suffix=")" prefixOverrides="and" >
<foreach collection="criteria.criteria" item="criterion" >
<choose >
<when test="criterion.noValue" >
and ${criterion.condition}
</when>
<when test="criterion.singleValue" >
and ${criterion.condition} #{criterion.value}
</when>
<when test="criterion.betweenValue" >
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
</when>
<when test="criterion.listValue" >
and ${criterion.condition}
<foreach collection="criterion.value" item="listItem" open="(" close=")" separator="," >
#{listItem}
</foreach>
</when>
</choose>
</foreach>
</trim>
</if>
</foreach>
</where>
</sql>

最佳答案

我已经弄清楚是什么原因导致了这个问题。 (与myBatis生成过程无关。)

当我将实用程序包添加到 Eclipse 构建路径时出现问题,其中包括具有许多旧包的第三方库。我怀疑有问题的包是旧的 org.apache.xerces.parsers。

我通过从头开始构建 Eclipse 项目并一次添加一个包和代码来发现该错误。

运行时错误(SQL 语句中的未知元素 <#comment>)可以通过添加项目来重现,并通过从构建路径中删除项目来消除。

关于java - 生成文件中的 MyBatis 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5407564/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com