Springboot普通类调用mapper

@RequestMapping("")
@MapperScan(“awsa.jatham.cloud.platform.mapper”)
@Component
public class H2Client {
//注入mappper
@Autowired
private UserMapper userMapper;
@Autowired
private DataNodeMapper dataNodeMapper;
public static H2Client h2Client;

@PostConstruct
public void init(){
    h2Client = this;
    h2Client.dataNodeMapper = this.dataNodeMapper;
}

需要注解
@Component
@Autowired 自动装配
@PostConstruct
被@PostConstruct修饰的方法会在服务器加载Servlet的时候运行,并且只会被服务器调用一次,类似于Serclet的inti()方法。被@PostConstruct修饰的方法会在构造函数之后,init()方法之前运行。

发布了3 篇原创文章 · 获赞 0 · 访问量 54

猜你喜欢

转载自blog.csdn.net/qq_42784606/article/details/102929293