在封装的时候,发现普通类注入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);
网友评论