提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档
文章目录
解决方法
普通类使用@Component注解修饰,添加本类型静态属性、所需mapper属性,添加init方法,用@PostConstruct注解修饰,方法内初始化以上2个属性:
@Component
public class VideoPool {
private static VideoPool that; // 本类型静态属性
@Resource
public VideoMapper videoMapper; // 所需要mapper
@PostConstruct
public void init() {
that = this;
that.videoMapper = this.videoMapper;
}
}
在类中需要使用mapper时,用that(本类型静态属性).mapper:
public static void run() {
List<Item> itemList = that.itemMapper.getAll();
}
更多内容见个人博客