老男孩linux网站,温州市建设工程质量安全管理总站,网站怎么做图片动态,北滘网站建设错误代码#xff1a;
Service层接口interface PCI{}
接口实现类Serviceclass PCIImpt imeplements PCI{}Controller层Autowiredprivate PCIImpt pciImpt; //注入了实现类在没有使用maven管理的时候注入实现类编译一直未报错#xff0c;也就是说编译可以通过#xff0c;但…错误代码
Service层接口interface PCI{}
接口实现类Serviceclass PCIImpt imeplements PCI{}Controller层Autowiredprivate PCIImpt pciImpt; //注入了实现类在没有使用maven管理的时候注入实现类编译一直未报错也就是说编译可以通过但是使用maven管理后编译报错。 而正确的写法
Controller层Autowiredprivate PCI pci; //注入接口以Autowired自动接收
结果编译通过结论就是注入的是实现类对象接收的接口理解为多态Controller–Service–ServiceImpt–Mapper 要遵循Controller–Service接口–ServiceImpt实现类–Mapper接口模式 那么在Service接口有多个ServiceImpt实现类的情况就需要指定参数名来选择哪个ServiceImpt实现类了。 Service层此时有两个接口实现类Service(PCIImpt1)class PCIImpt1 imeplements PCI{}Service(PCIimpt2)class PCIImpt2 imeplements PCI{}Controller层Resource(namePCIimpt2) //填PCIimpt1注入PCIimpt1实现类填PCIimpt2则注入PCIimpt2实现类private PCI pci; //注入接口以Resource手动指定接收同理在ServiceImpt实现类中也是通过Mapper接口来接收即
ServiceImpt实现类Autowiredprivate Mapper mapper;