diff --git a/src/main/java/io/company/localhost/common/dto/MapDto.java b/src/main/java/io/company/localhost/common/dto/MapDto.java index 9025b05..ec17348 100644 --- a/src/main/java/io/company/localhost/common/dto/MapDto.java +++ b/src/main/java/io/company/localhost/common/dto/MapDto.java @@ -19,6 +19,7 @@ import org.springframework.util.ObjectUtils; import java.io.Serial; import java.math.BigDecimal; +import java.math.BigInteger; import java.util.Map; public class MapDto extends ListOrderedMap { @@ -56,5 +57,23 @@ public class MapDto extends ListOrderedMap { // key에 해당하는 값을 String으로 가져오고, BigDecimal로 변환하여 반환 return ObjectUtils.isEmpty(get(key)) ? null : new BigDecimal(getString(key)); } + + /** + * 주어진 키에 해당하는 값을 Integer 타입으로 반환합니다. + * 값이 BigInteger인 경우 자동으로 int로 변환합니다. + * + * @param key Map에서 값을 검색할 키 + * @return 해당 키에 대한 값(Integer 타입), 값이 없으면 null + */ + public Integer getInt(String key) { + Object value = get(key); + if (value instanceof BigInteger) { + return ((BigInteger) value).intValue(); + } else if (value instanceof Integer) { + return (Integer) value; + } + return null; + } + }