【Mybatis】如何继承Mybatis中的Mapper

本文介绍了在Mybatis中如何实现Mapper接口的继承,通过修改命名空间、避免Mapper接口扫描,使得SrcTestMapperExt接口能继承SrcTestMapper的功能。详细步骤包括:设置相同的命名空间、理解Mybatis的命名空间检查机制以及修改Spring的配置来避免基础Mapper被加载。
摘要由CSDN通过智能技术生成

int insertSelective(SrcTest record);

List selectByExample(SrcTestExample example);

SrcTest selectByPrimaryKey(Integer id);

int updateByExampleSelective(@Param(“record”) SrcTest record, @Param(“example”) SrcTestExample example);

int updateByExample(@Param(“record”) SrcTest record, @Param(“example”) SrcTestExample example);

int updateByPrimaryKeySelective(SrcTest record);

int updateByPrimaryKey(SrcTest record);

}

SrcTestMapperExt.java


package com.test.dao.mapper.srctest;

import com.test.dao.model.srctest.SrcTest;

import org.apache.ibatis.annotations.Param;

import javax.annotation.Resource;

import java.util.List;

/**

  • SrcTestMapperExt接口

  • Created by shirenchuang on 2018/6/30.

*/

@Resource

public interface SrcTestMapperExt extends SrcTestMapper {

List selectExtTest(@Param(“age”) int age);

}

SrcTestMapper.xml


<?xml version="1.0" encoding="UTF-8"?>

SrcTestMapperExt.xml


<?xml version="1.0" encoding="UTF-8"?>

select * from src_test where age>#{age}

注意:这里返回的resultMap=“BaseResultMap” 这个Map并没有再这个xml中定义,这样能使用吗?

上面是我生成的代码;并且能够正常使用;

那么SrcTestMapperExt.xml是如何继承SrcTestMapper.xml中的定义的呢?

1. 修改命名空间,使他们的命名空间相同

  • 13
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值