<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.digital.sfplan.mapper.SfPlanTaskMapper">
<select id="list" resultMap="idResult11">
select * from dep_sfplan_task
</select>
<resultMap type="com.digital.sfplan.model.SfPlanTaskDbModel" id="idResult11">
<id property="taskId" column="taskId"/>
<result property="periodId" column="periodId"/>
<result property="taskType" column="taskType"/>
<association property="sfPlanPeirodModel" javaType="com.digital.sfplan.model.SfPlanPeriodDbModel">
<id property="periodId" column="periodId"/>
<result property="planId" column="planId"/>
<result property="periodType" column="periodType"/>
</association>
</resultMap>
</mapper>
直接这样写,不会帮你自动匹配的。
所以其实 select和column是搭档
然后搞了个两层嵌套
<?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.digital.sfplan.mapper.SfPlanTaskMapper">
<select id="list" resultMap="idResult11">
select * from dep_sfplan_task
</select>
<resultMap type="com.digital.sfplan.model.SfPlanTaskDbModel" id="idResult11">
<id property="taskId" column="taskId"/>
<result property="periodId" column="periodId"/>
<result property="taskType" column="taskType"/>
<result property="startAt" column="startAt"/>
<result property="weekOfTaskStart" column="weekOfTaskStart"/>
<result property="daysOfTaskStart" column="daysOfTaskStart"/>
<result property="displayOfTaskStart" column="displayOfTaskStart"/>
<result property="message" column="message"/>
<result property="unsubscribe" column="unsubscribe"/>
<result property="enabled" column="enabled"/>
<result property="createTime" column="createTime"/>
<result property="creatorId" column="creatorId"/>
<result property="updateTime" column="updateTime"/>
<result property="updatorId" column="updatorId"/>
<result property="deleteFlag" column="deleteFlag"/>
<association property="sfPlanPeirodModel" column="periodId" select="idGetPeriod">
<id property="periodId" column="periodId"/>
<result property="planId" column="planId"/>
<result property="periodType" column="periodType"/>
<association property="sfPlanModel" column="planId" javaType="com.digital.sfplan.model.SfPlanDbModel" select="idGetPlan111">
<id property="planId111" column="planId"/>
<result property="title" column="title"/>
<result property="departmentId" column="departmentId"/>
<result property="doctorId" column="doctorId"/>
<result property="comment" column="comment"/>
<result property="enabled" column="enabled"/>
<result property="createTime" column="createTime"/>
<result property="creatorId" column="creatorId"/>
<result property="updateTime" column="updateTime"/>
<result property="updatorId" column="updatorId"/>
<result property="deleteFlag" column="deleteFlag"/>
</association>
</association>
</resultMap>
<select id="idGetPeriod" parameterType="java.lang.String" resultType="com.digital.sfplan.model.SfPlanPeriodDbModel">
SELECT periodId,planId,periodType FROM dep_sfplan_period
</select>
<select id="idGetPlan111" parameterType="java.lang.String" resultType="com.digital.sfplan.model.SfPlanDbModel">
SELECT planId as ,title,departmentId,doctorId,comment,enabled,createTime,creatorId,updateTime,updatorId,deleteFlag FROM dep_sfplan
</select>
</mapper>
第二层竟然怎么也匹配不上。百思不得骑姐。最终也没弄明白为什么。
最终只能用大杀器,一个sql语句。
<?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.digital.sfplan.mapper.SfPlanTaskMapper">
<select id="list" resultMap="idResult11">
select * from dep_sfplan_task a,dep_sfplan_period b,dep_sfplan c where a.periodId=b.periodId and c.planId=b.planId
</select>
<resultMap type="com.digital.sfplan.model.SfPlanTaskDbModel" id="idResult11">
<id property="taskId" column="taskId"/>
<result property="periodId" column="periodId"/>
<result property="taskType" column="taskType"/>
<result property="startAt" column="startAt"/>
<result property="weekOfTaskStart" column="weekOfTaskStart"/>
<result property="daysOfTaskStart" column="daysOfTaskStart"/>
<result property="displayOfTaskStart" column="displayOfTaskStart"/>
<result property="message" column="message"/>
<result property="unsubscribe" column="unsubscribe"/>
<result property="enabled" column="enabled"/>
<result property="createTime" column="createTime"/>
<result property="creatorId" column="creatorId"/>
<result property="updateTime" column="updateTime"/>
<result property="updatorId" column="updatorId"/>
<result property="deleteFlag" column="deleteFlag"/>
<association property="sfPlanPeirodModel" javaType="com.digital.sfplan.model.SfPlanPeriodDbModel">
<id property="periodId" column="periodId"/>
<result property="planId" column="planId"/>
<result property="periodType" column="periodType"/>
<association property="sfPlanModel" javaType="com.digital.sfplan.model.SfPlanDbModel" >
<id property="planId" column="planId"/>
<result property="title" column="title"/>
<result property="departmentId" column="departmentId"/>
<result property="doctorId" column="doctorId"/>
<result property="comment" column="comment"/>
<result property="enabled" column="enabled"/>
<result property="createTime" column="createTime"/>
<result property="creatorId" column="creatorId"/>
<result property="updateTime" column="updateTime"/>
<result property="updatorId" column="updatorId"/>
<result property="deleteFlag" column="deleteFlag"/>
</association>
</association>
</resultMap>
<select id="idGetPeriod" parameterType="java.lang.String" resultType="com.digital.sfplan.model.SfPlanPeriodDbModel">
SELECT periodId,planId,periodType FROM dep_sfplan_period
</select>
<select id="idGetPlan111" parameterType="java.lang.String" resultType="com.digital.sfplan.model.SfPlanDbModel">
SELECT planId ,title,departmentId,doctorId,comment,enabled,createTime,creatorId,updateTime,updatorId,deleteFlag FROM dep_sfplan
</select>
</mapper>