一次从两张表中查询 两条sql语句
如下面:从admin表查管理员信息 然后从角色表查该管理员对应的角色:
<resultMap id="adminMap" type="Admin">
<id column="id" property="id" ></id>
<result column="account" property="account"></result>
<result column="phone" property="phone"></result>
<result column="head_img" property="head_img"></result>
<collection select="findAdminListID" column="id"
property="roles" javaType="list" ofType="Role" >
</collection>
</resultMap>
<select id="findAdminList" resultType="Admin" resultMap="adminMap">
SELECT
a.id,
a.account,
a.phone,
a.head_img
FROM
admin a
WHERE type = 1
</select>
<select id="findAdminListID" resultType="Role">
SELECT
r.name
FROM
admin_role ar
LEFT JOIN role r
ON ar.roleid =r.id
WHERE ar.adminid =#{id}
</select>