다음 코드가 있습니다. 그것은 잘 작동합니다. 예외는 없습니다. 표준 쿼리로 검색된 JPA Entity 객체의 목록을 반복합니다 (따라서 목록에 null
개체가 없습니다). 목록에있는 루프에서 객체가 0
의 contractManagerID
이있는 경우 한 줄은 발사되도록신비 NullPointerException
for (PeriodicalTable periodical : resultsP){
stringFor.add(periodical.getReference());
site = em.find(SiteTable.class, periodical.getSiteID());
if (site != null && site.getPostcode() != null && !site.getPostcode().equals("")){
tempString = site.getPostcode().replaceAll("\\s+", " ");
periodical.setPostcode(tempString.trim());
}
}
지금, 나는 if
문에 추가했습니다. 아래에 표시;
for (PeriodicalTable periodical : resultsP){
if(periodical.getContractManagerID()==0) //<---- HERE!!!!
{
stringFor.add(periodical.getReference());
}
site = em.find(SiteTable.class, periodical.getSiteID());
if (site != null && site.getPostcode() != null && !site.getPostcode().equals("")){
tempString = site.getPostcode().replaceAll("\\s+", " ");
periodical.setPostcode(tempString.trim());
}
}
는 ("여기"로 표시),하지만 난 그게 할 수있는 방법을 이해하지 않습니다. null
개체가 목록에 없다는 것을 알고 있습니다. 그렇지 않으면 if 문 없이도 작동하지 않을 것이므로 개체가 없으면 제대로 작동하기 때문입니다. 나는 완전히 잃어 버렸다.
'getContractManagerID()'에 의해 반환되는 것은 무엇입니까? –
'periodical.getContractManagerID()'자체가 null이 아닌가요? – Bathsheba
'getContractManagerID()'는 Integer를 반환합니다. 데이터베이스에는 null 값이 없지만 if 문이 포화 상태가 아니더라도 확실하게 수행 할 수 있습니까? –