@Component
public class ResultAddOrEditUtil {
@Autowired
ICarTaskRecordDetailsService iCarTaskRecordDetailsService;
private static ResultAddOrEditUtil resultAddOrEditUtil1;
@PostConstruct
public void init() {
resultAddOrEditUtil1 = this;
resultAddOrEditUtil1.iCarTaskRecordDetailsService = this.iCarTaskRecordDetailsService;
}
//方法中使用service
public boolean returnDataAddOrUpdate(){
resultAddOrEditUtil1.iCarTaskRecordDetailsService.list();
}
}
二、使用bean
@Component
public class JedisUtil {
@Autowired
private User user;
private static JedisUtil jedisUtil;
@PostConstruct
public void init(){
jedisUtil=this;
jedisUtil.user= this.user;
}
}
总结:
①工具类要添加@Component注解
②定义工具类静态实体: private static JedisUtil jedisUtil
③定义初始化方法,并在方法上添加@PostConstruct注解
④使用:通过工具类的静态对象调用。例如: resultAddOrEditUtil1.iCarTaskRecordDetailsService.list()
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)