参考:https://blog.csdn.net/wqc19920906/article/details/80009929
1、注解方式:
@Component
public class TestUtils {
@Autowired
private ItemService itemService;
@Autowired
private ItemMapper itemMapper;
public static TestUtils testUtils;
@PostConstruct
public void init() {
testUtils = this;
}
//utils工具类中使用service和mapper接口的方法例子,用"testUtils.xxx.方法" 就可以了
public static void test(Item record){
testUtils.itemMapper.insert(record);
testUtils.itemService.queryAll();
}
}