1.在当前类上加注解@Component

@Component
public class CommandUtil {}

2.加入私有化mapper

@Autowired
private TaskMapper taskMapper;

3.添加当前类的静态属性

public static CommandUtil commandUtil;

4.添加初始化方法并引入@PostConstruct注解用于注入bean

@PostConstruct
public void init(){
	commandUtil = this ;
    commandUtil.taskMapper = this.taskMapper;
}

5.引入mapper

commandUtil.taskMapper.selectTask(taskId);
Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐