mybatis 两个实体类一个List怎么写sql和map映射
1个回答
展开全部
user和LawerCheckImg是吗?这个list用collection映射。。
<?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.mybatis.demo.role.dao.RoleDAO">
<resultMap id="RoleMap" type="Role">
<id property="id" column="r_id" />
<result property="roleName" column="rolename" />
<result property="roleDescription" column="roledescription" />
<collection property="lawerCheckImg" column="lawer_id" ofType="LawerCheckImg" javaType="ArrayList" resultMap="ModuleMap"/>
</resultMap>
<resultMap id="ModuleMap" type="Module">
<id property="id" column="m_id" />
<result property="moduleName" column="modulename" />
<result property="moduleDescription" column="moduledescription" />
</resultMap>
<select id="getRoles" resultMap="RoleMap" >
select
r.id as r_id , r.rolename, r.roledescription,
m.id as m_id, modulename, moduledescription,
rm.id as rm_id, rm.roleid, rm.moduleid
from roles r
left outer join role_module rm on r.id=rm.roleid
left outer join modules m on m.id= rm.moduleid
</select>
</mapper>
<?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.mybatis.demo.role.dao.RoleDAO">
<resultMap id="RoleMap" type="Role">
<id property="id" column="r_id" />
<result property="roleName" column="rolename" />
<result property="roleDescription" column="roledescription" />
<collection property="lawerCheckImg" column="lawer_id" ofType="LawerCheckImg" javaType="ArrayList" resultMap="ModuleMap"/>
</resultMap>
<resultMap id="ModuleMap" type="Module">
<id property="id" column="m_id" />
<result property="moduleName" column="modulename" />
<result property="moduleDescription" column="moduledescription" />
</resultMap>
<select id="getRoles" resultMap="RoleMap" >
select
r.id as r_id , r.rolename, r.roledescription,
m.id as m_id, modulename, moduledescription,
rm.id as rm_id, rm.roleid, rm.moduleid
from roles r
left outer join role_module rm on r.id=rm.roleid
left outer join modules m on m.id= rm.moduleid
</select>
</mapper>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询