实体类如下,bagNoList是String的List

    1. @Builder
    2. @Data
    3. @AllArgsConstructor
    4. @NoArgsConstructor
    5. public class LineHaulPlateDTO implements Serializable {
    6. private static final long serialVersionUID = 1091703593667681149L;
    7. @JsonSerialize(using = ToStringSerializer.class)
    8. private Long id;
    9. private Integer aggregatorId;
    10. private String lineHaulUuid;
    11. private String plateNo;
    12. private Integer bagCount;
    13. private Double length;
    14. private Double width;
    15. private Double height;
    16. private List<String> bagNoList = new ArrayList<>();
    17. }

    重点在于设置property和ofType

    1. <resultMap id="LineHaulPlateAndBagNoMap" type="com.xxx.LineHaulPlateDTO">
    2. <id column="ID" property="id" />
    3. <result column="LINE_HAUL_UUID" property="lineHaulUuid" />
    4. <result column="PLATE_NO" property="plateNo" />
    5. <result column="BAG_COUNT" property="bagCount" />
    6. <result column="LENGTH" property="length" />
    7. <result column="WIDTH" property="width" />
    8. <result column="HEIGHT" property="height" />
    9. <collection property="bagNoList" ofType="java.lang.String">
    10. <result column="BAG_NO"/>
    11. </collection>
    12. </resultMap>