美文网首页
springMVC普通类中调用mapper或service接口

springMVC普通类中调用mapper或service接口

作者: Restart白蓝 | 来源:发表于2021-03-27 16:52 被阅读0次

    在封装的时候,发现普通类注入mapper都为null,在网上看到多种解决方案,写一遍记录一下。

    @Component
    public class MutualStepPage {
        private UserMapper userMapper;
    
        public static MutualStepPage mutualStepPage;
    
        @Autowired
        public MutualStepPage(UserMapper userMapper) {
            this.userMapper = userMapper;
        }
    
        @PostConstruct
        public void init() {
            mutualStepPage = this;
        }
        //可以正常使用
    }
         mutualStepPage.userMapper.FindUserByToken(token);
    

    相关文章

      网友评论

          本文标题:springMVC普通类中调用mapper或service接口

          本文链接:https://www.haomeiwen.com/subject/jksyhltx.html