一个关系Lists,三个实体Worker、Student、Extinguisher,涉及多表查询from list, student, extinguisher where … 现在要
映射到Lists类中,在关系类中创建实体对象
然后写Mapper.xml映射,resultMap和association(巨容易写错)
type和javaType要带路径
column和数据库列名一致
property要和实体类成员变量完全一致
id标签似乎是去重?
<?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.jd.lists.dao.IListsDao">
<resultMap type="com.jd.vo.Lists" id="ListsResultMap">
<id column="lid" property="lId"/>
<result column="lstate" property="lState"/>
<association property="worker" javaType="com.jd.vo.Worker">
<id column="wid" property="wId"/>
<result column="wname" property="wName"/>
<result column="wphone" property="wPhone"/>
</association>
<association property="extinguisher" javaType="com.jd.vo.Extinguisher">
<id column="eid" property="eId"/>
<result column="etype" property="eType"/>
<result column="edesc" property="eDesc"/>
<result column="eposi" property="ePosi"/>
</association>
</resultMap>
<select id="selStuQuePro" resultMap="ListsResultMap">
select
lstate,
etype,
edesc,
eposi,
wname,
wphone
from
extinguisher,
list,
worker
where
lsid = #{sid}
and leid = eid
and lwid = wid
</select>
</mapper>