Mybatis exception: Could not find result map Java.util.Map problem analysis and solution

When using mybatis, I will share with you the pits that I or my colleagues have stepped on. Students who have other questions to share are welcome to communicate~

Phenomenon: There is no exception in compilation. When calling related services, Could not find result map Java.util.Map appears. Regardless of calling mybatis update, delete, insert, and get methods, similar exceptions are thrown.

Analysis: On this basis, the Mapper.xml file is generally incremental, and new functions are constantly added. If the original is good, you should realize that there is a problem with the new addition~, well, how to locate it?

Solution: For students who have problems for the first time, you can annotate and run the newly added codes one by one (of course, you can use half-search, but if there are many mistakes, it is not recommended). Although this method is stupid, it is not suitable for newbies ( It is a more realistic method if you don't know enough about the source code of mybatis). If you meet a lot of old drivers, you basically know how to find this problem. Summarize several situations:

1. Wrong way of writing  <select id="getXXX" resultMap="java.util.Map" > The original meaning is to return a map. Personally, it is not recommended to return a map. It is recommended to return an entity bean. The resultMap corresponds to the Mapper.xml file. <resultMap id="" /> tag, yes, yes, this is it, and if you want to return a map, you should use resultType

Correct spelling:  <select id="getXXX" resultType ="java.util.Map" >

2. When using the @ annotation with Mapper.xml, in order to facilitate expansion, I used ExtMapper.xml to inherit the implementation of Mapper.xml, which is beneficial to add/delete fields without changing ExtMapper.xml. In the actual project, I want to use the annotation type implementation of @update and @Select, which is convenient to write. However, ExtMapper.xml is more flexible to organize data. At this time, when calling @ResultMap(id="BaseResultMap"), there will also be The exception Could not find result map Java.util.Map, the general solution is to add the domain name to the id, such as @ResultMap(id="com.xxx.xxx.BaseResultMap"). Of course, the official itself still recommends using the full XML form. The main reason for this problem may be the simple writing of the annotation type.

Welcome to exchange and correct~



Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324604175&siteId=291194637