String.length()>1 报空指针异常
@Override
public ExpertEntity getExpertById(Long id) {
ExpertEntity Expert = ExpertMapper.getObjectById(id);
if (Expert.getFilepath().length()>1) {
...
}
return Expert;
}
对象的Stirng的length大于1就进行操作,很理想对不对,然而报空指针错误
解决方案:
@Override
public ExpertEntity getExpertById(Long id) {
ExpertEntity Expert = ExpertMapper.getObjectById(id);
if (Expert.getFilepath()!=null && Expert.getFilepath().length()>1) {
...
}
return Expert;
}