Mybatis全局配置文件


<?xml version="1.0" encoding="UTF-8" ?>
DOCTYPE configuration
        PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-config.dtd">

    
    

    
    
        
    

    
    
        
        
        
        <package name="com.lzr.bean">package>
        
    
    
    default="development">
        
            
            
                
                
                
                
            
        
    

    
    
        
        
        
        
    

    
    
    
        
        
        class="com.lzr.dao.EmployeeMapperAnnotation">
        
        
    
<?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">

    
    
#EmployeeMapperAnnotation.java
package com.lzr.dao;

import com.lzr.bean.Employee;
import org.apache.ibatis.annotations.Select;

/**
 * @author GGBond
 * @create 2021-05-24-9:41
 */
public interface EmployeeMapperAnnotation {
    @Select("select * from tbl_employee where id=#{id}")
    public Employee getEmpById(Integer id);
}
@Test
    public void test02() throws IOException{
        SqlSessionFactory sqlSessionFactory = getSqlSessionFactory();
        SqlSession openSession = sqlSessionFactory.openSession();
        try {
            EmployeeMapperAnnotation mapper = openSession.getMapper(EmployeeMapperAnnotation.class);
            Employee empById = mapper.getEmpById(1);
            System.out.println(empById);
        }finally {
            openSession.close();
        }

    }