<?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.bjsxt.mapper.UserMapper">

    <!--配置结果集和对象的映射关系-->
    <resultMap id="userMapper" type="com.bjsxt.pojo.Users">
        <id property="username" column="username"/>
        <result property="userpwd" column="userpwd"/>
         <!--配置关联对象Roles 单个对象时   javaType属性：Roles是哪个对象-->
        <association property="roles" javaType="com.bjsxt.pojo.Roles">
            <!--将结果集的哪些列添加到这个Roles对象的哪些属性中-->
            <id property="roleid" column="roleid"/>
            <result property="rolename" column="rolename"/>
        </association>
        <!--配置关联对象Menus 多个Menus对象用List存放   ofType属性：Menus的全名 -->
        <collection property="menus" ofType="com.bjsxt.pojo.Menus">
            <id property="menuid" column="menuid"/>
            <result property="menuname" column="menuname"/>
            <result property="menuurl" column="menuurl"/>
            <result property="fatherid" column="fatherid"/>
        </collection>
        <!--配置关联对象funs对象-->
        <collection property="funs" ofType="com.bjsxt.pojo.Funs">
            <id property="funid" column="funid"/>
            <result property="funname" column="funame"/>
            <result property="funurl" column="funurl"/>
        </collection>
    </resultMap>

    <select id="selectUserByName" parameterType="string" resultMap="userMapper">
        SELECT
            *
        FROM
            users u,
            roles r,
            roles_menus rm,
            menus m LEFT JOIN funs f ON m.menuid = f.menu_id
        WHERE
            u.role_id = r.roleid
          AND r.roleid = rm.roles_id
          AND rm.menus_id = m.menuid
          AND u.username = #{username}
    </select>
</mapper>
