Mapper icon indicating copy to clipboard operation
Mapper copied to clipboard

Unable to put different providers in one self-defined common mapper while using annotation-based dynamic routing

Open YuanHao97 opened this issue 2 years ago • 2 comments

I'm trying to put all different Provider methods in one mapper: BaseSelectProvider.class,BaseUpdateProvider.class, etc

@DatasourceRouting("ds1")
@tk.mybatis.mapper.annotation.RegisterMapper
public interface DS1Mapper<T> {
    @SelectProvider(type = BaseSelectProvider.class, method = "dynamicSQL")
    T selectOne(T record);
    @InsertProvider(type = BaseInsertProvider.class, method = "dynamicSQL")
    int insert(T record);
}

The annotation DatasourceRouting is used to do dynamic routing, so the common mapper need to be put in one mapper. However I got this error: 一个通用Mapper中只允许存在一个MapperTemplate子类。 Is it possible to add more than 1 Provider in one class? As far as I can see from source code, it is possible to add more than one MapperTemplate in tk.mybatis.mapper.mapperhelper.MapperHelper#fromMapperClass.

YuanHao97 avatar Feb 21 '24 06:02 YuanHao97

可以将两个接口方法定义到不同接口中,然后通过extends继承到一个接口中。

abel533 avatar Feb 21 '24 06:02 abel533

放两个接口是可以的,但是有两个问题

  1. 没太明白为啥一个类一定要限制一个provider,为啥不都放一起呢
  2. 我这个使用场景,是希望利用注解实现动态路由。如果放多个接口,每个继承的接口都需要加动态路由的注解,感觉这样不是很合适。如果都放一个类,就只用一个注解解决了

YuanHao97 avatar Feb 21 '24 13:02 YuanHao97

@abel533 帮忙review下pr

YuanHao97 avatar Feb 29 '24 10:02 YuanHao97