MyBatis中Mapper代理方式
Mapper 的动态代理作用
目前使用sqlsession进行增删改查的缺点:
- 没有办法实现多参数的传递
- 书写的时候没有接口,后期的维护就比较的低
解决的方案:
Mapper的代理方式实现增删改查
1.配置接口
package com.erwin.mapper;
import com.erwin.entity.Student;
import org.apache.ibatis.annotations.Select;
import java.util.List;
public interface StudentMapper03 {
List<Student> selectIf(String name, String gender);
}
接口中指明函数名,参数列表和返回值类型
2.配置Mapper层xml
注意最好将Mapper层xml与上述接口放在同一个package下,如下图:
注意,mapper层的命名空间在代理方式下必须与上述接口对应
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-/