Result Maps collection does not contain value for XXX 错误

时间:2022-07-22
本文章向大家介绍Result Maps collection does not contain value for XXX 错误,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

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

  • 错误原因: resultMap和resultType弄混淆了
    • resultMap:需要指明id和返回类型以及表字段的对应关系
    • resultType:返回一个自定义的实体类型,如图的com.sukai.entity.student
  • 解决方案: 把resultMap修改为resultType