MyBatis处理多对一关联对象映射的两种方法
1、举例说明:多个demo对应demo1实体对象;
package com.liwei.shiro.model;
public class Demo {
private String name;
private Integer age;
private String password;
private Demo1 d1;
省略set,get方法
}
}

2、创建demo1对象;
public class Demo1 {
private String name;
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
}

3、创建demo的dao层,创建service。此处省略。
配置dao的代理对象mapper文件。
<resultMap type="cn.itcast.domain.Demo" id="ordersUserResultMap">
<id column="id" property="id"/>
<result column="name" property="name"/>
<result column="age'" property="age"/>
<result column="password" property="password"/>

4、<association property="demo1" javaType="cn.itcast.domain.Demo1">
<id column="id" property="id"/>
<result column="name" property="name"/>
</association>
</resultMap>

5、此处resultMap对应 id,
<select id="findOrdersUserResultMap" resultMap="ordersUserResultMap">
select * from demo d,demo1 d1 where demo.id = demo1.id
</select>

6、方法二直接返回map集合,
<select id="findOrdersUserResultMap" resultMap="ordersUserResultMap">
select d.id as id,a.name as name,d.age as age,d.password as word ,d1.name as name1 from demo d,demo1 d1 where demo.id = demo1.id
</select>

7、此方法直接将两个对象的属性直接封装在map集合里面,用的时候直接去,相当于在entity层创建dto层;当然,也可以在entity创建dto层,返回dto实体对象;
