个人资源分享网站:http://xiaocaoshare.com/
1.创建父接口
public interface ActivityBase {
}
2.分别创建三个实现类
@Service
public class ExperienceAct implements ActivityBase{
}
@Service
public class GroupAct implements ActivityBase{
}
@Service
public class InviteCardAct implements ActivityBase{
}
@RestController
@RequestMapping("")
public class ActiveController {
@Autowired
private Map<String, ActivityBase> activityBaseMap;
@GetMapping("")
public void test(){
System.out.println(activityBaseMap.getClass().getName());
for(Map.Entry<String,ActivityBase> map:activityBaseMap.entrySet()){
System.out.println(map.getKey()+"=========>"+map.getValue().getClass().getName());
}
}
}
4.启动程序并使用postMan调用这个接口,看控制台输出
java.util.LinkedHashMap
experienceAct=========>com.xiao.ActivityDesign.ExperienceAct
groupAct=========>com.xiao.ActivityDesign.GroupAct
inviteCardAct=========>com.xiao.ActivityDesign.InviteCardAct