在使用多线程的时候 实现Runnable 方法并重写 run()方法,怎么在run中使用 mapper操作数据库?
使用 @Autowired 注入mapper 报 空 (Exception in thread "main" java.lang.NullPointerException)
@Autowired
private FillIdleMapper mapper;
@Override
public void run() {
//具体实现逻辑代码
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
String flowId = "572912406616461312";
String mxName = "CUSTOMER_PRODUCT";
List<TxRecordRegistryBack> list= mapper.getTxList(flowId,mxName);
if (list != null && list.size()>0){
for (int i = 0; i < list.size(); i++) {
TxRecordRegistryBack back =list.get(i);
log.info("========时间======"+new Date());
log.info("========返回的对象数据======"+i+" 参数:"+back);
}
}
}
![img](https://img-mid.csdnimg.cn/release/static/image/mid/ask/093043141556117.png "#left")