这个例子中的mybatis-config.xml文件,引用这个文件即可   
src/main/java/com.atguigu.pojo/Employee.javapackage  com. atguigu. pojo ; public  class  Employee  { private  Integer  id; private  String  name; private  String  plone; public  Integer  getId ( )  { return  id; } public  void  setId ( Integer  id)  { this . id =  id; } public  String  getName ( )  { return  name; } public  void  setName ( String  name)  { this . name =  name; } public  String  getPlone ( )  { return  plone; } public  void  setPlone ( String  plone)  { this . plone =  plone; } @Override public  String  toString ( )  { return  "Employee{"  +  "id="  +  id +  ", name='"  +  name +  '\''  +  ", plone='"  +  plone +  '\''  +  '}' ; } 
} src/main/java/com.atguigu.mapper/EmployeeMapper.javapackage  com. atguigu. mapper ; import  com. atguigu. pojo.  Employee ; 
import  org. apache. ibatis. annotations.  Param ; import  java. util.  List ; 
import  java. util.  Map ; public  interface  EmployeeMapper  { 根据id查看员工信息Employee  queryById ( Integer  id) ; 根据id删除员工信息(单个简单类型作为参数)int  deleteById ( Integer  id) ; 根据 plone 查询员工的信息(单个简单类型作为参数)List < Employee > queryByPlone ( String  plone) ; 插入员工数据(单个实体对象作为参数)int  insertEmp ( Employee  employee) ; 传入多个简单类型的参数List < Employee > queryByNameAndPlone ( @Param ( "xname" )  String  name,  @Param ( "xplone" )  String  plone) ; 传入 map类型的参数int  insertEmpMap ( Map  data) ; -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - 查询工资高于传入值的员工姓名们List < String > queryNamesBySalary ( @Param ( "salary" )  Double  salary) ; 返回集合类型,查询全部员工信息List < Employee > queryAll ( ) ; 返回map类型,查询城市的最高工资和平均工资Map < String ,  Object > selectEmpNameAndMaxSalary ( ) ; 自增长主键回显,自动提交事务int  insertUser ( Employee  employee) ; -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - mybatis自己维护非自增主键int  insertEmployee ( Employee  employee) ; Employee  queryByIdd ( String  tId) ; 
} src/main/resources/mappers/EmployeeMapper.xml
<?xml version="1.0" encoding="UTF-8" ?> 
<! DOCTYPE  mapper PUBLIC  "-//mybatis.org//DTO Config 3.0//EN" "https://mybatis.org/dtd/mybatis-3-mapper.dtd" > < mappernamespace = " com.atguigu.mapper.EmployeeMapper" > < selectid = " queryById" resultType = " com.atguigu.pojo.Employee" > </ select> < deleteid = " deleteById" > </ delete> < selectid = " queryByPlone" resultType = " com.atguigu.pojo.Employee" > </ select> < insertid = " insertEmp" > </ insert> < selectid = " queryByNameAndPlone" resultType = " com.atguigu.pojo.Employee" > </ select> < insertid = " insertEmpMap" > </ insert> < selectid = " queryNamesBySalary" resultType = " string" > </ select> < typeAliases> < packagename = " com.atguigu.pojo" /> </ typeAliases> < selectid = " queryAll" resultType = " employee" > </ select> < selectid = " selectEmpNameAndMaxSalary" resultType = " map" > </ select> < insertid = " insertUser" useGeneratedKeys = " true" keyColumn = " id" keyProperty = " id" > </ insert> < insertid = " insertEmployee" > < selectKeyorder = " BEFORE" resultType = " string" keyProperty = " tId" > </ selectKey> </ insert> < settingname = " mapUnderscoreToCamelCase" value = " true" /> < selectid = " queryById" resultMap = " id" > < resultMapid = " tMap" type = " teacher" > < idcolumn = " t_id" property = " tId" /> < resultcolumn = " t_name" property = " tName" /> </ resultMap> < selectid = " queryByIdd" resultMap = " tMap" > </ select> </ mapper> src/test/java/com.atguigu.MybatisTest.java
package  com. atguigu. test ; import  com. atguigu. mapper.  EmployeeMapper ; 
import  com. atguigu. pojo.  Employee ; 
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  org. junit. jupiter. api.  Test ; import  java. io.  IOException ; 
import  java. io.  InputStream ; public  class  MybatisTest  { @Test public  void  test_01 ( )  throws  IOException  { 1 、读取外部配置文件( mybatis- config. xml) 使用MyBatis 提供的Resources 类,读取名为mybatis- config. xml的配置文件。InputStream  ips =  Resources . getResourceAsStream ( "mybatis-config.xml" ) ; 2 、创建sqlSessionFactory使用SqlSessionFactoryBuilder 根据配置文件构建SqlSessionFactory 对象。SqlSessionFactory  sqlSessionFactory =  new  SqlSessionFactoryBuilder ( ) . build ( ips) ; 3 、根据sqlSessionFactory创建sqlSession对象【自动开启JDBC 】【自动开启事务,但不会自动提交事务,需要sqlSession. commit ( ) 手动开启】或者使用 sqlSessionFactory. openSession ( true ) 【会自动开启事务,自动提交事务,不需要写sqlSession. commit ( ) 】SqlSession  sqlSession =  sqlSessionFactory. openSession ( ) ; 4 、使用SqlSession 的getMapper ( ) 方法,获取EmployeeMapper 接口的代理对象,并且调用具体的SQL 方法EmployeeMapper  mapper =  sqlSession. getMapper ( EmployeeMapper . class ) ; 调用EmployeeMapper 接口的queryById ( ) 方法,传入参数1 ,执行查询操作,并将结果赋值给employee对象。Employee  employee =  mapper. queryById ( 1 ) ; System . out. println ( employee) ; 5 、提交事务(非DQL )和释放资源sqlSession. commit ( ) :提交事务,但是在这个查询操作的上下文中,commit是不必要的,因为查询操作不需要提交事务。通常,只有DML (如INSERT 、UPDATE 、DELETE )操作才需要提交事务。sqlSession. commit ( ) ; sqlSession. close ( ) ; } 
}