实现CommandLineRunner接口,重写run方法
package com.example.qw_goods.utils;
import com.example.qw_common.model.GoodsVO;
import com.example.qw_goods.service.GoodsService;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
/**
* @author qw
* @Description
* @date 25/4/2022
*/
@Component
public class RunnerLoadOne implements CommandLineRunner {
static Map<String,Object> urlMap = new HashMap<>();
@Resource
private GoodsService goodsService ;
@Override
public void run(String... args) throws Exception {
List<GoodsVO> goodsList = goodsService.getGoodsList();
Optional.ofNullable(goodsList).ifPresent(list->{
urlMap.put("url",list.get(0).getCode());
urlMap.put("soapUrl",list.get(0).getName());
});
}
public static Map<String,Object> getInfo(){
return urlMap;
}
}