java在普通类中调用mapper、service
初始化,添加类名静态字段,加上postConstruct注解,用于注入bean
比如有如下类想要调用registUserMapper,则实现如下:
@Component // 如果类之前没有这个注解,一定要加上 public class RegisterRpcService { // 添加类名静态字段 public static RegisterRpcService registerRpcService; // 注入mapper @Resource private RegistUserMapper registUserMapper; // 注入bean @PostConstruct public void init() { registerRpcService = this; registerRpcService.registUserMapper = this.registUserMapper; } // 然后即可如下使用 registerRpcService.registUserMapper.${Method} }