通过Mapper代理实现自定义接口
- 自定义接口,定义相关业务方法
- 编写与方法对应的Mapper.xml
1、自定义接口
2、创建接口对应的Mapper.xml,定义接口方法对应的SQL语句
- statement标签可根据SQL执行的业务选择insert、delete、update,select。
- MyBatis框架会根据规则自动创建接口实现类的代理对象。
规则:
- Mapper.xml中namespace为接口的全类名。
- Mapper.xml中statement的id为接口中对应的方法名。
- Mapper.xml中statement的parameterType和接口中对应方法的参数类型一致。
- Mapper.xml中statement的resultType和接口中对应方法的返回值类型一致。
3、在config.xml中注册AccountRepository.xml
4、调用接口的代理对象完成相关的业务操作;