How do resultType and resultMap differ in MyBatis? How do you map nested objects and collections?
Short answer
resultType lets MyBatis map columns to fields by name on its own, fine for flat results. resultMap is a hand-declared mapping, used when names differ or you need nested objects and child lists built from a JOIN.
3 points to say:
- Turn on
map-underscore-to-camel-caseto need fewerresultMaps. - Building a child
Listfrom a JOIN needs aresultMap. <id>decides how JOIN rows are merged.
Keep reading the deep dive
Create a free account to read the full explanation and follow-up questions, mark questions as studied and review them on a schedule.