Tech/SpringBoot
-
JPA - JoinTech/SpringBoot 2019. 12. 8. 11:55
커뮤니티 게시판 테이블 쿼리: 특정 직업을 가진 사람들이 쓴 글의 정보와 사용자 정보를 조회하는 SQL 는 다음과 같을 것이다 select t.topic_seq '번호',t.title '제목',m.name '작성자',p.title '직업',t.created_at '작성일' from `member` m join `topic` t on m.member_seq = t.member_seq join `profile` p on p.profile_seq = m.profile_seq where p.profile_seq=1; query 결과는 아래와 같을 것이다. JPA 로 해당 부분을 구현 하는 과정은 아래와 같다. JPAQueryFactory 설..
-
spring controller async request process with executorTech/SpringBoot 2019. 10. 5. 16:35
스프링에서 컨트롤러에서 요청에 대한 처리를 동기가 아닌 비동기 처리하는 방식을 제공 하고있다. 스프링5 의 webflux 사용한다면 해당 비동기 처리를 사용할 수 있지만 스프링 5 버전 이하의 시스템에서는 해당 처리가 필요할 것이다. 스프링이 제공하는 방식 비동기로 처리하기 위해 스프링에서 여러가지 반환 유형을 제공한다. 요청에 대해 즉각 응답을 주는것이 아닌 요청에 대한 처리를 백그라운드로 처리하여 완료시 사용자에게 반환 함으로써 요청 처리에 대한 병목을 없애도록 한다. 스프링이 제공하는 비동기 응답 > 다른 스레드로 생성된 비동기 결과 > > DefferedResult > > ListenableFuture > > CompletionStage > > CompletableFuture > > 연산 후 생성..
-
Java 8 Stream rangeTech/SpringBoot 2019. 8. 24. 15:18
// 1~10000 사이의 숫자를 문자열 리스트로 반환 List ids = LongStream.range(1,10000) .boxed() .map(String::valueOf).collect(Collectors.toList()); //1~10000 사이의 숫자를 콤마로 분리한 문자열 생성 String strIds = LongStream.range(1,10000) .boxed() .map(String::valueOf) .collect(Collectors.joining(","));
-
usage spring data jpa with query dslTech/SpringBoot 2019. 7. 14. 17:27
-- dependency com.querydsl querydsl-apt com.querydsl querydsl-jpa org.springframework.boot spring-boot-maven-plugin com.mysema.maven apt-maven-plugin 1.1.3 process target/generated-sources/java com.querydsl.apt.jpa.JPAAnnotationProcessor -- created databaseConfig.java @Configuration public class Databaseconfig { @Bean public JPAQueryFactory queryFactory(EntityManager em) { return new JPAQueryFac..
-
Spring Batch (정리)Tech/SpringBoot 2019. 4. 6. 14:25
해당 글은 과 기타 를 참고하여 정리한 내용 입니다. Spring Boot Batch 장점 - 대용량 데이터 처리에 최적화 - 효과적인 통계처리와 같은 재사용 가능한 필수 기능 지원 - 자동화 처리 - 예외사항과 비정상 동작에 대한 방어 기능 Spring Boot Batch 주의 사항 - 복잡한 구조와 로직을 피할것 - 데이터 무결성을 유지하는 유효성 검사 등의 방어책 필요 - 잦은 I/O 사용 최소화를 위한 개발 필요 - Batch 처리시 다른 프로젝트에 영향을 주는지 확인 할것 - Spring boot batch 는 스케줄러를 제공 하지 않음 해결책: Quartz Framework, Jenkins 장점: Quartz 사용시 클러스터링 및 다양한 스케줄링, 실행 이력 관리가능 비추천: 리눅스의 cron..
-
Object List groupping and sorted by fieldsTech/SpringBoot 2019. 1. 9. 11:33
public class Country { // 출력 순서 private int display; // 국가 이름 private String name; }국가 리스트를 출력 순서를 우선으로 정렬 후 국가이름으로 정렬 하도록 한다. - display 가 동일한 그룹을 맵으로 만들도록 한다.- 키값에 해당하는 리스트를 이름순으로 정렬한다.public List sortedByDisplayAndName(List countryList){ Map map = new TreeMap(); for (Country m: countryList) { int key = m.getDisplay(); if(map.containsKey(key)){ List list = map.get(key); list.add(m); }else{ List..
-
자바 - 시작_종료 시간 사이 체크Tech/SpringBoot 2018. 10. 8. 19:19
/** * 현재 시간이 시작,종료시간 사이에 있는지 체크 하도록 한다. * 현재 시간이 시작,종료 시간 사이일 경우 true 아닐 경우 false * @param start * @param end * @param now * @return */ private static boolean checkTimeBetween(LocalTime start, LocalTime end, LocalTime now) { if (start.isAfter(end)) { return !now.isBefore(start) || !now.isAfter(end); } else { return !now.isBefore(start) && !now.isAfter(end); } }
-
spring boot exception 처리를 위한 enum 클래스 활용Tech/SpringBoot 2018. 9. 15. 13:59
오류 발생시 json 형태의 커스텀한 객체를 던지고 싶다.예외처리시 오류 코드와 오류 메시지는 enum 클래스를 활용한다. 케이스별 예외에 대한 정의를 enum 으로 정의 한다. public enum ServiceError { BIND_ERROR(){ @Override public ResultError getResultError() { String message = getMessage(); return ResultError.builder() .httpStatus(HttpStatus.BAD_REQUEST) .resultCode("40000") .resultMessage(StringUtils.isEmpty(message) ? "Binding Error." : message) .build(); } }, EMA..
-
Spring boot jar 파일 Linux 서버 실행 등록 하기Tech/SpringBoot 2018. 9. 12. 14:00
### Spring boot Linux 서버 실행 등록 하기 * step 01 [maven 수정] ```xml org.springframework.boot spring-boot-maven-plugin true ```` * step 02 [시스템 서비스 등록] sudo vi /etc/systemd/system/서비스명.service ```sql [Unit] Description=설명 추가 After=networking.service [Service] User= ExecStart=/XXX.jar SuccessExitStatus=143 WorkingDirectory= [Install] WantedBy=multi-user.target ``` * step 03 [실행 가능 파일로 변경] chmod +x XXXX...