知識點:在service層中注入其它的service接口或者mapper接口都是可以的
但是在封裝的Utils工具類中或者非controller普通類中使用@Autowired@Resource注解注入Service或者Mapper接口,直接注入會出現問題
參考博客:https://blog.csdn.net/qiulingxin/article/details/78068314
解決辦法:
@Component
public class ReadExcel {
@Resource
private OrgMapper orgMapper;
//如果僅僅使用以上接口注入不行,mapper.xx為null
這是需要添加以下代碼即可
public static ReadExcel readExcel;
@PostConstruct
public void init(){
readExcel=this;
}
在ReadExcel工具類中,使用mapper接口的方法例子。使用"ReadExcel.orgMapper.xxx"
public Json insertOrg(){
Json json = new Json();
List<Org> orgList =readExcel.orgMapper.getOrgByOrgName(org_name);
return json;
}
}
