zoukankan      html  css  js  c++  java
  • Spring @Autowired注解在utils静态工具类

    【转】

    使用场景:在一个静态方法中,如何使用以下注入;

    @Autowired 
    private ItemMapper itemMapper;
    @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(); } }
    很多事情不是看到希望才去坚持,而是坚持了才会看到希望
  • 相关阅读:
    自我介绍
    币值转换
    打印沙漏
    对我影响最大的三位老师

    pta
    pta-3
    学习计划
    对我有影响的三个老师
    介绍自己
  • 原文地址:https://www.cnblogs.com/isisbenben/p/6228748.html
Copyright © 2011-2022 走看看