null체크하는 if문

김희주·2025년 10월 30일
0

자잘한 Tip

목록 보기
8/8
  • asis
BigDecimal resultPmtPstvTax;
if(strPmtPstvTax == null || strPmtPstvTax.trim().isEmpty()) {
	resultPmtPstvTax = null;
} else {
	resultPmtPstvTax = new BigDecimal(strPmtPstvTax.replace(",", "").trim()
}
  • tobe
		BigDecimal resultPmtPstvTax = (strPmtPstvTax == null || strPmtPstvTax.trim().isEmpty())? null : new BigDecimal(strPmtPstvTax.replace(",", "").trim());

그리고

StringUtils.hasText(in.getTaxpyrRsdntRgstrnNbr()

이렇게 하면 hasText가 null체크도 포함함

틀린거

		out.setTbVatCrdSalsRcvdRptM(crdSalsRcvdRptResult == null ? new TbVatCrdSalsRcvdRptM() : crdSalsRcvdRptResult.get(0));

맞는거

List<TbVatCrdSalsRcvdRptM> crdSalsRcvdRptResult = tbVatCrdSalsRcvdRptMDao.selectByExt(tbVatCrdSalsRcvdRptMExt);
out.setTbVatCrdSalsRcvdRptM(
    (crdSalsRcvdRptResult == null || crdSalsRcvdRptResult.isEmpty()) 
        ? new TbVatCrdSalsRcvdRptM() 
        : crdSalsRcvdRptResult.get(0)
);

리스트 null 체크

			if(!CollectionUtils.isEmpty(in.getTargetInfo())) {
profile
백엔드 개발자입니다 ☘

0개의 댓글