官网的示例
<resultMap id="detailedBlogResultMap" type="Blog">
<constructor>
<idArg column="blog_id" javaType="int"/>
</constructor>
<result property="title" column="blog_title"/>
<association property="author" javaType="Author">
<id property="id" column="author_id"/>
<result property="username" column="author_username"/>
<result property="password" column="author_password"/>
<result property="email" column="author_email"/>
<result property="bio" column="author_bio"/>
<result property="favouriteSection" column="author_favourite_section"/>
</association>
<collection property="posts" ofType="Post">
<id property="id" column="post_id"/>
<result property="subject" column="post_subject"/>
<association property="author" javaType="Author"/>
<collection property="comments" ofType="Comment">
<id property="id" column="comment_id"/>
</collection>
<collection property="tags" ofType="Tag" >
<id property="id" column="tag_id"/>
</collection>
<discriminator javaType="int" column="draft">
<case value="1" resultType="DraftPost"/>
</discriminator>
</collection>
</resultMap>
官网的例子实际使用中存在一些问题,比如collection标签中再嵌套,idea中没有提示,且查不出来;将嵌套的元素都改成resultmap后可用,记录如下;
例子
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.xxx.mapper.TargetTblMapper">
<select id="getOneDayList" resultMap="EvaluateObjectMap">
SELECT
target_tbl.id AS T_id,
target_tbl.sname AS T_sname,
target_tbl.type AS T_type,
target_tbl.serial_number AS T_serial_number,
target_tbl.development_stage AS T_development_stage,
target_tbl.code AS T_code,
target_tbl.status AS T_status,
test_info_tbl.id AS INFO_id,
test_info_tbl.tester_number AS INFO_tester_number,
test_info_tbl.target_tbl_id AS INFO_target_tbl_id,
test_info_tbl.test_project AS INFO_test_project,
test_info_tbl.test_type AS INFO_test_type,
test_info_tbl.start_time AS INFO_start_time,
test_info_tbl.end_time AS INFO_end_time,
test_info_tbl.temprature AS INFO_temprature,
test_info_tbl.humidity AS INFO_humidity,
test_point_tbl.id AS POINT_id,
test_point_tbl.test_point_name AS POINT_test_point_name,
test_point_tbl.test_point_value AS POINT_test_point_value,
test_point_tbl.test_info_tbl_id AS POINT_test_info_tbl_id,
test_point_tbl.calibration_data AS POINT_calibration_data
FROM
target_tbl
LEFT JOIN test_info_tbl ON target_tbl.id = test_info_tbl.target_tbl_id
LEFT JOIN test_point_tbl ON test_info_tbl.id = test_point_tbl.test_info_tbl_id
WHERE DATE_FORMAT(test_info_tbl.start_time,'%Y-%m-%d') = #{date}
</select>
<resultMap id="EvaluateObjectMap" type="com.xxx.dto.EvaluateObject">
<id column="T_id"/>
<association property="targetTbl" javaType="com.xxx.entity.TargetTbl">
<id property="id" column="T_id"/>
<result property="sname" column="T_sname"/>
<result property="type" column="T_type"/>
<result property="serialNumber" column="T_serial_number"/>
<result property="developmentStage" column="T_development_stage"/>
<result property="code" column="T_code"/>
<result property="status" column="T_status"/>
</association>
<collection property="testItemList" ofType="com.xxx.dto.TestItem" resultMap="TestItemMap"/>
</resultMap>
<resultMap id="TestItemMap" type="com.xxx.dto.TestItem">
<association property="testInfoTbl" resultMap="TestInfoTblMap"/>
<collection property="testPointTblList" ofType="com.xxx.entity.TestPointTbl" resultMap="TestPointTblMap"/>
</resultMap>
<resultMap id="TestPointTblMap" type="com.xxx.entity.TestPointTbl">
<id property="id" column="POINT_id"/>
<result property="testPointName" column="POINT_test_point_name"/>
<result property="testPointValue" column="POINT_test_point_value"/>
<result property="testInfoTblId" column="POINT_test_info_tbl_id"/>
<result property="calibrationData" column="POINT_calibration_data"/>
</resultMap>
<resultMap id="TestInfoTblMap" type="com.xxx.entity.TestInfoTbl">
<id property="id" column="INFO_id"/>
<result property="testerNumber" column="INFO_tester_number"/>
<result property="targetTblId" column="INFO_target_tbl_id"/>
<result property="testProject" column="INFO_test_project"/>
<result property="testType" column="INFO_test_type"/>
<result property="startTime" column="INFO_start_time"/>
<result property="endTime" column="INFO_end_time"/>
<result property="temprature" column="INFO_temprature"/>
<result property="humidity" column="INFO_humidity"/>
</resultMap>
</mapper>