1.エラーを再現します
エラープロンプト:
13:41:33.539 ERROR com.fast.framework.advice.FastBootControllerAdvice 58 errorHandler - Could not find result map java.util.List org.apache.ibatis.builder.IncompleteElementException: Could not find result map java.util.List
at org.apache.ibatis.builder.MapperBuilderAssistant.getStatementResultMaps(MapperBuilderAssistant.java:346) ~[mybatis-3.5.0.jar:3.5.0]
at org.apache.ibatis.builder.MapperBuilderAssistant.addMappedStatement(MapperBuilderAssistant.java:290) ~[mybatis-3.5.0.jar:3.5.0]
at org.apache.ibatis.builder.xml.XMLStatementBuilder.parseStatementNode(XMLStatementBuilder.java:109) ~[mybatis-3.5.0.jar:3.5.0]
at org.apache.ibatis.session.Configuration.lambda$buildAllStatements$2(Configuration.java:787) ~[mybatis-3.5.0.jar:3.5.0]
at java.util.Collection.removeIf(Collection.java:414) ~[?:1.8.0_112]
at org.apache.ibatis.session.Configuration.buildAllStatements(Configuration.java:786) ~[mybatis-3.5.0.jar:3.5.0]
at org.apache.ibatis.session.Configuration.hasStatement(Configuration.java:763) ~[mybatis-3.5.0.jar:3.5.0]
at org.apache.ibatis.session.Configuration.hasStatement(Configuration.java:758) ~[mybatis-3.5.0.jar:3.5.0]
at com.baomidou.mybatisplus.core.override.MybatisMapperMethod$SqlCommand.resolveMappedStatement(MybatisMapperMethod.java:264) ~[mybatis-plus-core-3.1.0
2.背景
まず、公式サイトにアクセスして、resultMapとresultTypeの使い方が正しいことを確認してください。この記事では基本的な使い方については説明していませんので、myabtisを上手に使った後のエラーについては
公式ウェブサイト:http://www.mybatis.org/mybatis-3/zh/sqlmap-xml.html#select
3.シーンを回復します
(1)Daoレイヤーには2つの方法がありますが、これら2つの高速は正常であり、テストは間違っていることに注意してください
int selectFast();
int selectTest();
(2)selectTestに問題があるxmlに対応して、resultMap = "java.util.List"の記述が間違っている
<select id="selectFast" resultType="java.lang.Integer">
select count(1) from sys_user
</select>
<select id="selectTest" resultMap="java.util.List">
select count(1) from sys_user
</select>
(3)次に、通常のメソッドint selectFast();のみを呼び出します。
masterDao.selectFast()
(4)通常のMavenのクリーンアップ、インストール、およびパッケージ化はすべて正常です
(5)コンパイルして起動すると、正常に起動します
(6)次に、通常のメソッドselectFastがコントローラーを介して呼び出されると、初期エラーが報告されます。
結果マップjava.util.Listが見つかりませんでした
(7)このエラーと同様に、エラーが発生した場所のヒントがあります。このエラーのヒントは次のとおりです。
com.fast.web.controller.TestController.getString(TestController.java:25)〜[classes /:?]
これはこのTestControllerの25行目です。私もこのメソッドを呼び出しました。
(8)しかし、間違った問題は何ですか?
メソッドintselectFast();現在呼び出しているメソッドは正常です。コードに問題はなく、呼び出し元のインターフェイスはこのメソッドのみであるため、コードは正常に実行されます。
しかし、mybatisはエラーを返し、その時点でのインターフェイス呼び出しに関係のないメソッド(int selectTest();)を返しました。ただし、このエラーは、コンパイルフェーズと起動フェーズでエラーを報告しませんでした。他のメソッドを呼び出すと、このメソッドのエラーが表示され、エラーの位置は正しいメソッドの位置になります。
アイデア:最初に問題を解決してから問題を明確にし、無関係なメソッドのエラーを直接修正し、次のように変更します。intselectTest();メソッドは正常であり、再訪問のプロンプトは正常です。
<select id="selectTest" resultType="java.lang.Integer">
select count(1) from sys_user
</select>
当時の解決策はデバッグでした:私が要求した通常のメソッドのため、returnパラメーターはresultTypeである必要がありますが、このresultMapはどこから来たのか、エラーも報告されました。mybatisによって表示されるエラーメッセージの場所を確認してください。
14:04:46.787 ERROR com.fast.framework.advice.FastBootControllerAdvice 58 errorHandler - Could not find result map java.util.List org.apache.ibatis.builder.IncompleteElementException: Could not find result map java.util.List
at org.apache.ibatis.builder.MapperBuilderAssistant.getStatementResultMaps(MapperBuilderAssistant.java:346) ~[mybatis-3.5.0.jar:3.5.0]
at org.apache.ibatis.builder.MapperBuilderAssistant.addMappedStatement(MapperBuilderAssistant.java:290) ~[mybatis-3.5.0.jar:3.5.0]
at org.apache.ibatis.builder.xml.XMLStatementBuilder.parseStatementNode(XMLStatementBuilder.java:109) ~[mybatis-3.5.0.jar:3.5.0]
at org.apache.ibatis.session.Configuration.lambda$buildAllStatements$2(Configuration.java:787) ~[mybatis-3.5.0.jar:3.5.0]
at java.util.Collection.removeIf(Collection.java:414) ~[?:1.8.0_112]
これ(XMLStatementBuilder.java:109)を見つけて、ブレークポイントを作成します。以下はmybatisのソースコードです。ブレークポイントは最後の行に配置されます。
再リクエストしてください。送信されたresultMapパラメータを参照してください
public void parseStatementNode() {
String id = this.context.getStringAttribute("id");
String databaseId = this.context.getStringAttribute("databaseId");
if (this.databaseIdMatchesCurrent(id, databaseId, this.requiredDatabaseId)) {
Integer fetchSize = this.context.getIntAttribute("fetchSize");
Integer timeout = this.context.getIntAttribute("timeout");
String parameterMap = this.context.getStringAttribute("parameterMap");
String parameterType = this.context.getStringAttribute("parameterType");
Class<?> parameterTypeClass = this.resolveClass(parameterType);
String resultMap = this.context.getStringAttribute("resultMap");
String resultType = this.context.getStringAttribute("resultType");
String lang = this.context.getStringAttribute("lang");
LanguageDriver langDriver = this.getLanguageDriver(lang);
Class<?> resultTypeClass = this.resolveClass(resultType);
String resultSetType = this.context.getStringAttribute("resultSetType");
StatementType statementType = StatementType.valueOf(this.context.getStringAttribute("statementType", StatementType.PREPARED.toString()));
ResultSetType resultSetTypeEnum = this.resolveResultSetType(resultSetType);
String nodeName = this.context.getNode().getNodeName();
SqlCommandType sqlCommandType = SqlCommandType.valueOf(nodeName.toUpperCase(Locale.ENGLISH));
boolean isSelect = sqlCommandType == SqlCommandType.SELECT;
boolean flushCache = this.context.getBooleanAttribute("flushCache", !isSelect);
boolean useCache = this.context.getBooleanAttribute("useCache", isSelect);
boolean resultOrdered = this.context.getBooleanAttribute("resultOrdered", false);
XMLIncludeTransformer includeParser = new XMLIncludeTransformer(this.configuration, this.builderAssistant);
includeParser.applyIncludes(this.context.getNode());
this.processSelectKeyNodes(id, parameterTypeClass, langDriver);
SqlSource sqlSource = langDriver.createSqlSource(this.configuration, this.context, parameterTypeClass);
String resultSets = this.context.getStringAttribute("resultSets");
String keyProperty = this.context.getStringAttribute("keyProperty");
String keyColumn = this.context.getStringAttribute("keyColumn");
String keyStatementId = id + "!selectKey";
keyStatementId = this.builderAssistant.applyCurrentNamespace(keyStatementId, true);
Object keyGenerator;
if (this.configuration.hasKeyGenerator(keyStatementId)) {
keyGenerator = this.configuration.getKeyGenerator(keyStatementId);
} else {
keyGenerator = this.context.getBooleanAttribute("useGeneratedKeys", this.configuration.isUseGeneratedKeys() && SqlCommandType.INSERT.equals(sqlCommandType)) ? Jdbc3KeyGenerator.INSTANCE : NoKeyGenerator.INSTANCE;
}
this.builderAssistant.addMappedStatement(id, sqlSource, statementType, sqlCommandType, fetchSize, timeout, parameterMap, parameterTypeClass, resultMap, resultTypeClass, resultSetTypeEnum, flushCache, useCache, resultOrdered, (KeyGenerator)keyGenerator, keyProperty, keyColumn, databaseId, langDriver, resultSets);
}
}
次に、デバッグパラメータを確認します。インターフェイスリクエストは通常のメソッドであるselectFast()ですが、この問題のあるメソッドであるselectTest()も確認しました。
resultMapはjava.util.Listを返します
したがって、selectTestメソッドをグローバルに検索し、戻りパラメーターを変更して、バグ修正を完了します。
概要:このバグは、複雑なバグ、また意味のバグではありません、。。。通常のインターフェースが要求されたときには、エラーを報告せずにコンパイルし、開始をMyBatisの、無関係な方法のエラーが報告されている。このプロンプトの位置に問題がある、それは意志トラブルシューティングに多くの時間を浪費する原因になります。まず、この問題が発生することを忘れないでください。そうすれば、将来的にピットを回避できます。