본문 바로가기

전체 글

Spring Data JPA에서 @Query사용시 Parameter 기존 고x몰이라는 PHP 쇼핑몰을 Java/JPA로 전환하는중 DB 테이블에 1:1 매핑된 Entity로는 뭔가 CUD 관련 처리 하는게 불안해서, (실제 type이 망.. 단순 true/false가 고x몰 DB 하나의 테이블에 어떤 컬럼은 y / n 어떤 컬럼은 o / null 어떤 컬럼은 1 / 0 어떤 컬럼은 Y / N.....으..)그래서.. 가능하면 update시에 필요 entity를 별도 생성하거나 컬럼별 update를 하도록 하고 있다. 컬럼별 업데이트를 할 경우 여러개의 param을 사용하기도 하는데, 그냥 Object를 넘겨서 처리하는 것이 좀 더 깔끔해 보였다.(라고 나는 주장한다~~~~)  간단 간단한 업뎃의 예로.. 기존 : @Modi..@Query("update User set n.. 더보기
Stream 내 값에 대한 Distinct 처리 기본적인 중복 제거는 아래와 같이 distinct() 를 사용하는 것이다. 편하네.. List distinctNames = Arrays.asList("닉", "그리썸", "이블린", "그리썸", "호라시오", "맥", "이블린").stream().distinct().collect(Collectors.toList()); log.debug("DistinctNames = {}", distinctNames); 특정 오브젝트에 속성 값을 distinct() 할 경우는 아래와 같이 별도의 function을 만들어 처리한다. User.java @Getter @Setter @Builder @ToString class User { private String name; @Default private int age = 0;.. 더보기
Spring Security 에서 @Async 사용시 (threads) Context 공유하기 기본적으로는 @Async 사용시 SecurityContext가 공유되지 않는다. 즉, JPA의 Audit를 사용한 CRUD 실행시 @Async 를 적용하면 Null 오류가 출력된다. SecurityContextHolder.setStrategyName(SecurityContextHolder.MODE_INHERITABLETHREADLOCAL); 처리는 간단하게 SecurityConfiguration에 전파에 대한 지정만 해주면 된다. Async 처리 https://www.baeldung.com/spring-async How To Do @Async in Spring | Baeldung How to enable and use @Async in Spring - from the very simple config a.. 더보기
팁] Spring MVC Trim 처리 간혹, Form Object나 검색용 Dto같은 놈들의 String 항목에 Trim처리를 해야 할때가 있다. 예~~전에는 @Trim Annotation이나 직접 Trim처리를 하곤 했었던 아득한 기억이 있는데.. @ControllerAdvice public class XXXXControllerAdvice { @InitBinder public void initBinder(WebDataBinder binder) { binder.registerCustomEditor(String.class, new StringTrimmerEditor(true)); } ... 그냥 이렇게 써도 무난하리라 생각.. 더보기
Spring / QueryDSL int * int = long 의 경우 NumberPath 컬럼에 대응하는 값들을 multiply 처리해 쓰다보면 실제 결과는 int 를 넘어가는 상황을 맞이하게 된다. 이때 ea (int) * salePrice(int)의 경우 as사용시 당연하지만 NumberPath가 Integer로 지정된다. .. NumberPath totalSalePrice = Expressions.numberPath(Integer.class, "totalSalePrice"); .. qOrderItem.ea.sum().multiply(qOrderItem.salePrice.min()).as(totalSalePrice)) 근데 우린 장사가 잘되고 있으니 int의 범위를 훅 넘어버린다. 문제는 code에서 int로 했다고 해서 오류는 나지 않는다. (단지 결과만 음수처리되어.. 더보기