본문 바로가기
728x90
반응형

Back-end146

[NestJS] LOG에 요청 transation-id 추가하기 Nest JS에서 LOG에 요청 하나에 대한 트랜잭션 ID 를 넣어 구분 하고자 한다. NEST 에서 logging 은 인터셉션, 가드, 미들웨어 등에서 출력을 한다. transation-id 를 넣지 않으면 같은 시간에 요청이 올경우 , 응답이나 에러 가 어떤 요청 인지 구분하기 어렵다. 위에 표시된 숫자 ID는 프로세스 ID (=pid)로 다른 요청이 들어와도 같은 ID가 출력된다. 😎install npm i elastic-apm-node 😎import import * as apm from 'elastic-apm-node' APM 이란 APM은 Application Performance Monitoring의 약어로, Application에 대한 성능정보 및 발생한 Error정보 그리고 Applicat.. 2022. 9. 13.
[Nest.js] Interceptor VS Filter VS Middleware 차이점 Nest.js 에서 Interceptor VS Filter VS Middleware 세가지 모두 매우 유사한 개념이며, 사용자의 선호도 따라 결정됩니다. Nest.js의 라이프 사이클(Life Cycle) 1. 미들웨어 (Middleware) 2. 글로벌 가드 (Global Guards) 3. 컨트롤러-레벨 가드 (Controller-level Guards) 4. 메서드-레벨 가드 (Method-level Guards) 5. 글로벌 파이프 (Global Pipes) 6. 컨트롤러-레벨 파이프 (Controller-level Pipes) 7. 메서드-레벨 파이프 (Method-level Pipes) 8. 컨트롤러 및 프로바이더 (Controller & Provider) 9. 글로벌 인터셉터 (Global .. 2022. 9. 7.
[Java] 현재 날짜, 현재 시간 가져오기 _ Java 8 이후 Java 8 이후 java.time.LocalDate java.time.LocalTime java.time.LocalDateTime 현재 날짜(타임존 적용) 구하기 import java.time.LocalDate; import java.time.ZoneId; public class CurrentDateTime { public static void main(String[] args) { // 현재 날짜 구하기 (시스템 시계, 시스템 타임존) LocalDate now = LocalDate.now(); // 현재 날짜 구하기(Paris) LocalDate parisNow = LocalDate.now(ZoneId.of("Europe/Paris")); // 포맷 정의 DateTimeFormatter formatt.. 2022. 7. 11.
[JAVA] stream() 중복제거 Collectors.toList() List events = boardDao.getEvents(VO); events 리스트는 user No 가 중복된 리스트일때 List allUserNo = events.stream().map(EventVO::getUserNo).collect(Collectors.toList()); //중복 제거 되지 않은 상태 EventVO의 getUserNo만 뽑아서 다시 toList 리스트로 만들어준다. 예를 들면 allUserNo = ["10","10","10","10","11","11","11","12",] 중복제거가 되지 않았다. 이때, 중복제거를 위해 List userList = allUserNo.stream().distinct().collect(Collectors.toList()); stream().disti.. 2022. 6. 22.
[Java] excel poi 셀 배경색 지정 및 색 리스트 셀스타일 자바로 poi를 사용하여 엑셀 파일을 생성할 경우 셀의 배경색 및 정렬, 테두리, 폰트를 설정하는 예제 입니다. 배경색을 지정할때는 setFillForegroundColor 로 설정한 후 setFillPattern 으로 HSSFCellStyle.SOLID_FOREGROUND 를 지정해 주어야 적용이 됩니다. //테이블 타이틀 스타일 CellStyle cellStyle_Title = xssfWb.createCellStyle(); cellStyle_Title.setBorderTop(BorderStyle.THIN); //테두리 위쪽 cellStyle_Title.setBorderBottom(BorderStyle.THIN); //테두리 아래쪽 cellStyle_Title.setBorderLeft(BorderSty.. 2022. 4. 27.
[Java]두 날짜 사이의 개월 수 구하기 SimpleDateFormat df_Start = new SimpleDateFormat("yyyy-MM"); Date date_start = df_Start.parse(yyyymmStart); SimpleDateFormat df_end = new SimpleDateFormat("yyyy-MM"); Date date_end = df_end.parse(yyyymmEnd); long diff = date_end.getTime() - date_start.getTime(); int result = (int) ((diff / 1000) / 60 / 60 / 24 / 30); int sYear = Integer.parseInt(aa.substring(0, 4)); int sMonth = Integer.parseInt.. 2022. 4. 20.
[Java] 파일 다운로드 - 2가지 방식 😎방법 1 - response Flush 더보기 @Controller public class CommonController { @Resource(name="commonService") private CommonService commonService; @RequestMapping(value="/common/downloadFile.do") public void downloadFile(CommandMap commandMap, HttpServletResponse response) throws Exception{ Map map = commonService.selectFileInfo(commandMap.getMap()); String original_File_Name = (String)map.get("ORIGINA.. 2022. 4. 19.
[JAVA]브라우저별 한글 파일명 인코딩 _ excel파일 서버에서 프론트로 파일을 전송할 때 한글로 파일명을 보내면 깨지는 경우가 다반사입니다. 따라서 아래 로직과 같이 User-Agent header 값을 가져와서 브라우저 별로 인코딩을 해 줘야 한글이 깨지지 않고 정상 출력이 됩니다. String fileName = "한글파일명"; String name = "출력될파명이름"; // 브라우저 별 한글 인코딩 String header = request.getHeader("User-Agent"); if (header.contains("Edge")){ name = URLEncoder.encode(fileName, "UTF-8").replaceAll("\\+", "%20"); response.setHeader("Content-Disposition", "attachm.. 2022. 4. 19.
[JAVA] 간단한 폴더 존재여부 확인 해당 경로가 존재 하지 않을 경우가 있음으로, File Folder = new File(savePath); if (!Folder.exists()) { Folder.mkdir(); //폴더 생성 } 해당 폴더가 존재하지않으면 생성하는 간단코드 추가로 문제 방지 및 해결 2022. 4. 18.
728x90
반응형