Attribute "resultType" must be declared for element type "insert"或"update"

时间:2024-07-04 20:36:26

Attribute "resultType" must be declared for element type "insert"或"update"

今天写代码的时候,写mybatis的update语句和insert语句,写完之后,开jetty,但是很久过去,jetty卡卡住不动,

[logistics] 2016-02-01 16:40:54 577 main com.alibaba.druid.filter.logging.Log4jFilter.connectionLog(Log4jFilter.java:132)

[DEBUG] {conn-10010} setAutoCommit false

这个问题一般是xmL中有错误导致的,但是查看了很久,都没与发现,知道jetty运行超时,报错。看到报错日志。如下图:

Attribute "resultType" must be declared for element type "insert"或"update"

这个报错日志中说Attribute "resultType" must be declared for element type "insert",还有一个报错信息是Attribute "resultType" must be declared for element type "update"

当时一直没有找到那里有问题,一直以为问题是我写insert和update语句是没有写resultType,后来发现,问题恰恰出在此处。

因为在insert和update语句中是没有resultType的,报错的信息不是说没有写resultType,而是说要在mybatis的文件中声明resultType之后,才可以使用resultType.

在xml文件的开头一般有两行代码:


DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"

将http://mybatis.org/dtd/mybatis-3-mapper.dtd复制到浏览器中,会自动下载dtd文件,打开后,搜索update和insert和select,会发现之间的区别:

select的声明如下:


ATTLIST select
id CDATA #REQUIRED
parameterMap CDATA #IMPLIED
parameterType CDATA #IMPLIED
resultMap CDATA #IMPLIED
resultType CDATA #IMPLIED
resultSetType (FORWARD_ONLY | SCROLL_INSENSITIVE | SCROLL_SENSITIVE) #IMPLIED
statementType (STATEMENT|PREPARED|CALLABLE) #IMPLIED
fetchSize CDATA #IMPLIED
timeout CDATA #IMPLIED
flushCache (true|false) #IMPLIED
useCache (true|false) #IMPLIED
databaseId CDATA #IMPLIED
lang CDATA #IMPLIED
resultOrdered (true|false) #IMPLIED
resultSets CDATA #IMPLIED

insert的声明如下:


ATTLIST insert
id CDATA #REQUIRED
parameterMap CDATA #IMPLIED
parameterType CDATA #IMPLIED
timeout CDATA #IMPLIED
flushCache (true|false) #IMPLIED
statementType (STATEMENT|PREPARED|CALLABLE) #IMPLIED
keyProperty CDATA #IMPLIED
useGeneratedKeys (true|false) #IMPLIED
keyColumn CDATA #IMPLIED
databaseId CDATA #IMPLIED
lang CDATA #IMPLIED

update的声明如下:


ATTLIST update
id CDATA #REQUIRED
parameterMap CDATA #IMPLIED
parameterType CDATA #IMPLIED
timeout CDATA #IMPLIED
flushCache (true|false) #IMPLIED
statementType (STATEMENT|PREPARED|CALLABLE) #IMPLIED
keyProperty CDATA #IMPLIED
useGeneratedKeys (true|false) #IMPLIED
keyColumn CDATA #IMPLIED
databaseId CDATA #IMPLIED
lang CDATA #IMPLIED

可以看出select声明中有resultType,而update和insert中没有resultType

错误在此。