java一个接口拥有多个实现类,调用指定实现类

1、接口如下

/**
 * @author lichangyuan
 * @create 2021-02-26 0:37
 */
public interface OrdinaryService {
    JsonData queryByKeywordPagination(Integer page, Integer counts,Object parameter[]);
}

2、有如下两个实现
实现类一

@Service("maintenanceService")
public class MaintenanceServiceImpl implements MaintenanceService, OrdinaryService {
    @Override
    public JsonData queryByKeywordPagination(Integer page, Integer counts, Object[] parameter) {
        return null;
    }
}

实现类二

@Service("inspectionService")
public class InspectionServiceImpl implements InspectionService,OrdinaryService  {
    @Override
    public JsonData queryByKeywordPagination(Integer page, Integer counts, Object[] parameter) {
        return null;
    }
}

3、根据不同的条件调用不同的实现
方法一

@Resource(name="maintenanceService")
OrdinaryService maintenanceService;
	
@Resource(name="inspectionService")
OrdinaryService inspectionService;

方法二

@Autowired
@Qualifier("maintenanceService")
ShopPay weixinPay;
 
@Autowired
@Qualifier("inspectionService")
ShopPay aliPay;

你可能感兴趣的:(Spring,java,接口,设计模式)