mapper中的namespace

时间:2025-04-20 17:09:56

在MyBatis中,Mapper中的namespace用于绑定Dao接口的,即面向接口编程,它的功能和Dao接口的实现类Impl相当,但是他不用写接口实现类,通过namesapce(命名空间)的绑定直接通过id找到相应方法,执行相应的SQL语句。

Student stu = (1);

  

public interface StudentDao {
    public Student findById(Integer sid);

   }

<mapper namespace="">
    <resultMap  type="student">
        <id column="sid" property="sid"></id>
        <result column="sname" property="sname"></result>
        <collection property="courseList" javaType="list" ofType="course"
                    resultMap="">
        </collection>
    </resultMap>

    <select  parameterType="int" resultMap="stuMap">
        select s.* ,c.* from t_stu s
        inner join t_select ts
        on  = 
        inner join t_course c
        on  = 
        where  = #{sid};
    </select>
</mapper>