전체 글(10)
-
SSE(Server-Sent Events)
SSE 개념서버 -> 클라이언트 단방향 실시간 통신WebSocket과 달리 서버에서 클라이언트로만 데이터를 보냄HTTP 프로토콜 사용으로 별도 프로토콜 필요 없음자동 재접속 지원Repository 구조Key-Value 구조Key(String): "memberId_timeStamp" // 예: "123_1698985544"Value: SseEmitter 객체public interface EmitterRepository { void save(String emitterId, SseEmitter sseEmitter); void deleteById(String emitterId); Map findAllByIdStartWith(Long memberId);}@Repositorypublic class..
2024.11.06 -
정적 팩토리 메서드 네이밍의 차이 (of vs from)
public record FindCouponsResponse(List coupons) { public static FindCouponsResponse from(final List coupons) { return coupons.stream() .map(FindCouponResponse::from) .collect(Collectors.collectingAndThen(Collectors.toList(), FindCouponsResponse::new)); } public record FindCouponResponse(Long couponId, String name, String description, Integer discount..
2024.11.04 -
QueryDSL 아이템 목록 페이징 처리
private Predicate getHavingCondition(Long lastIdx, Long lastItemId, ItemSortType itemSortType) { return switch (itemSortType) { case NEW -> item.id.lt(lastIdx); case HIGHEST_AMOUNT -> item.price.lt(lastIdx) .or(item.price.eq(lastIdx.intValue()).and(item.id.gt(lastItemId))); case LOWEST_AMOUNT -> item.price.gt(lastIdx) .or(item.price.eq(lastId..
2024.10.31 -
StringUtils 라이브러리
프로젝트를 하면서 StringUtils 라이브러리를 골라해야했는데이전에 프로젝트를 하면서는 lang3를 사용했지만이번엔 대체 해보고싶어서 Sprignframwork.util을 사용했다org.springframework.util.StringUtils;org.apache.commons.lang3.StringUtils;.isEmpty() 메서드를 써야했는데둘이 기능은 비슷하게 하고 있었다.물론 lang3가 조금 더 많은 메서드를 제공해준다 org.springframework.util.StringUtils:null이거나 길이가 0인 문자열일 경우 true를 반환합니다.공백 문자만 있는 문자열(예: " ")은 비어있지 않은 것으로 간주합니다.b) Apache Commons Lang의 org.apache.commo..
2024.10.29