【在Util类中调用mapper方法】
在util工具类中调用mapper
·
在Util类中调用mapper方法
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);
更多推荐
已为社区贡献1条内容
所有评论(0)