java
Mapper 接口開發方法只須要程序員編寫Mapper 接口(至關於Dao 接口),由Mybatis 框架根據接口定義建立接口的動態代理對象,代理對象的方法體同上邊Dao接口實現類方法mysql
總結:接口代理方式,其實就咱們本身不用實現MapperImpl(持久層實現類),mybatis經過接口代理的方式幫助咱們實現git
Mapper 接口開發須要遵循如下規範:程序員
1) Mapper.xml文件中的namespace與mapper接口的全限定名相同github
2) Mapper接口方法名和Mapper.xml中定義的每一個statement的id相同sql
3) Mapper接口方法的輸入參數類型和mapper.xml中定義的每一個sql的parameterType的類型相同數據庫
4) Mapper接口方法的輸出參數類型和mapper.xml中定義的每一個sql的resultType的類型相同apache
以下圖:session
實現步驟:mybatis
刪除 mapper 層接口的實現類(新建一個項目mybatis02,將第一天的代碼所有複製過來)
修改映射配置文件
<!-- 將命名空間修改成StudentMapper全路徑名-->
<mapper namespace="com.itheima.mapper.StudentMapper">
修改 service 層接口的實現類,採用接口代理方式實現功能(由於如今沒有持久層實現類了,因此業務層沒法直接調用,須要本身實現而且調用代理接口方式的MapperImpl)
package com.itheima.service.impl;
import com.itheima.bean.Student;
import com.itheima.mapper.StudentMapper;
import com.itheima.service.StudentService;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
/*
業務層實現類
*/
public class StudentServiceImpl implements StudentService {