Result Maps collection does not contain value for XXX 错误

Result Maps collection does not contain value for XXX 错误

Scroll Down

Mybatis报错如下:

2020-05-14 11:56:25.887 ERROR 40074 --- [nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.apache.ibatis.builder.IncompleteElementException: **Could not find result map com.sukai.entity.Student] with root cause**

java.lang.IllegalArgumentException: Result Maps collection does not contain value for com.sukai.entity.Student

image-20200514115930804

  • 错误原因:

    resultMap和resultType弄混淆了

    • resultMap:需要指明id和返回类型以及表字段的对应关系
    • resultType:返回一个自定义的实体类型,如图的com.sukai.entity.student
  • 解决方案:

    把resultMap修改为resultType