Java中如何实现一个接口拥有多个实现类
1、接口
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") OrdinaryService maintenanceService; @Autowired @Qualifier("inspectionService") OrdinaryService inspectionService;