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

    <resultMap id="userMapper" type="user">
        <id property="userid" column="userid"/>
        <result property="username" column="username"/>
        <result property="userpwd" column="userpwd"/>
<!--        配置关联对象 一对一-->
        <association property="role" javaType="role">
            <id property="roleid" column="roleid"/>
            <result property="rolename" column="rolename"/>
        </association>
<!--        配关联对象 一对多-->
        <collection property="menus" ofType="menu">
            <id property="menuid" column="menuid"/>
            <result property="menuname" column="menuname"/>
            <result property="menuurl" column="menuurl"/>
            <result property="fatherid" column="fatherid"/>
        </collection>
    </resultMap>
    <select id="selectUser"  resultMap="userMapper">
        SELECT * from `user` u ,roles r,roles_menus rm ,menus m
        where u.rold_id=r.roleid and r.roleid=rm.roles_id and rm.menus_id=m.menuid
        and username = #{username} and userpwd = #{userpwd};
    </select>

    <select id="selectUserById" resultType="user">
        select  * from  user where userid = #{id};
    </select>

</mapper>