2023.07.13.목.TIL

heeh·2023년 7월 16일

TIL

목록 보기
42/82
post-thumbnail

2023.07.13.목

  • 프로그래머스
    • https://school.programmers.co.kr/learn/courses/30/lessons/120806

      class Solution {
              public int solution(int num1, int num2) {
                  int answer = 0;
                  answer = (int)(((double)num1 / num2) * 1000);
                  return answer;
              }
          }
    • num1 / num2 계산에서만 소수점이 필요하기 때문에 double로 강제 형변환을 해줌

    • (int)(((double)num1 / num2) * 1000); 앞에 int가 붙는 이유

      • int로 이미 num1, num2를 선언
      • answer를 이미 int로 선언
      • 계산식에서 이미 double로 소수점으로 만들어주어 필요한 계산을 맞췄기 때문에 앞에 int가 붙어도 됨 = 답에서는 소수점이 없음
    • 이것도 가능!

      public class Solution {
          public int solution(int num1, int num2) {
              int result = (int) (num1 / (double) num2 * 1000);
              return result;
          }
      }
      public class Solution {
          public int solution(int num1, int num2) {
              int result = (int) ((double)num1 / num2 * 1000);
              return result;
          }
      }
      • 하지만 완전한 안전을 위해 * 1000를 나누어(밖으로 빼기)주는 것이 좋음!
  • https://school.programmers.co.kr/learn/courses/30/lessons/120829
    class Solution {
            public int solution(int angle) {
                if (angle < 90) {
                    return 1;
                } else if (angle == 90) {
                    return 2;
                } else if (angle < 180) {
                    return 3;
                } else {
                    return 4;
                }
            }
        }
    • 90 < angle < 180return 3; 인데, 90 < 을 어떻게 넣어주지…?
      • 위에 angle < 90angle == 90 지정했기 때문에 자동으로 90 < angle < 180 가 설정됨
    • 연산자를 응용하고 싶다면?
      class Solution {
          public int solution(int angle) {
              int answer = 0;
              if(0 < angle && angle < 90) {
                  answer = 1;
              } else if(angle == 90) {
                  answer = 2;
              } else if(90 < angle && angle < 180) {
                  answer = 3;
              } else {
                  answer = 4;
              }
              return answer;
          }
      }
    • 삼항 연산자로 응용하고 싶다면?
      class Solution {
          public int solution(int angle) {
              return angle == 180 ? 4 : angle < 90 ? 1 : angle == 90 ? 2 : angle > 90 ? 3 : 0;
          }
      }

마이셀렉샵…

  • @Schrduler : 지정하는 특정 시간마다 메서드가 동작
    • @EnableJpaAuditing 걸었던 것 처럼 @EnableScheduling를 같은 곳에 적어주기
  • cron : 운영체제에서 특정 시간마다 작업을 자동 수행하게 해 주고 싶을 때 사용하는 명령어, 특정한 시간에 특정한 작업을 수행하게 해주는 Scheduling 역할
    • 초, 분, 시, 일, 월, 주 순서 → “0 0 1 * * *”
      → 매일 새벽 1시
  • @NotBlank
    • Bean validation
  • JwtAuthorizatinFilter
    • getJwtFromHeader : 순수한 토큰 뽑을 수 있음
    • has Text()로 확인 및 검증
    • Claims into : 정보 뽑기
    • Authentication : 인증 처리
      → setAuthentication 인증 처리
      → createAuthentication 인증 객체 생성
  • 정렬방법
    • DESC or ASC
      → 오름차순 or 내림차순

      Sort.Direction direction = isAsc ? Sort.Direction.ASC : Sort.Direction.DESC;
              Sort sort = Sort.by(direction, sorBy);
              Pageable pageable = PageRequest.of(page, size, sort);
  • .map
    • page 타입에서 제공하는 메서드
    • 그 page 타입에 들어있는 Product 데이터를 하나씩 돌리면서 Product 타입을 파라미터로 가지고 있는 ProductResponseDto 생성자 호출
      → 생성자의 의해서 생성하면 ProductResponseDto 전부 교체
      → 변환해서 convert해서 내보낼 수 있음
  • 필요할 때 조회할 수 있게! (fetch = FetchType.LAZY)
  • 양방향 관계 = (mapperBy = “”)
  • 전체를 찾고 User가 누구인지 User 기준으로 찾고 그리고 폴더 테이블의 이름도 찾는다, 이름은 한 개가 아닌 여러 개(In)
    • 여러 개를 한번에 조건을 주기 위해서 In이 필요

      findAllByUserAndNameIn(user, folderNames);

      → 폴더 레포지토리에 쿼리 메서드 만들기

  • 동적 처리하기 위해 model 사용
  • 프로젝트에 회원별로 등록한 폴더가 동적으로 보여지기 위해 추가
    return "index :: #fragment";
  • model
    model.addAttribute("folders", folderServicer.getFolders(userDetails.getUser()));
    • 회원 별로 등록한 폴더들을 가지고 와서 Thymeleaf index.html에 데이터를 Model을 통해서 전달
    • 내부적으로 동적으로 가져온 폴더 명이 쭉 찍힘
  • .iter
    product.getProductFolderList.iter
    for (ProductFolder productFolder : product.getProductFolderList()) {
                
            }
  • 지연로딩 사용은 영속성 컨텍스트(트랜잭셔널) 필요

페어프로그래밍

class Solution {
        public int[] solution(int[] emergency) {
            int[] answer = new int[emergency.length];
            for (int i = 0; i < emergency.length; i++) {
                for (int j = 0; j < emergency.length; j++) {
                    if (emergency[i] <= emergency[j]) {
                        answer[i] ++;
                    }
                }
            }
            return answer;
        }
    }
  • 외부 for문이 돌고 내부 for문이 돌면서 i가 j보다 작거나 같으면 +1이 됨
  • ex [3, 76, 24]
    • 3
      3 : 3 = 같음 +1
      3 : 76 = 작음 +1
      3 : 24 = 작음 +1
      
      3 = 3
    • 76
      76 : 3 =76 : 76 = 같음 +1
      76 : 24 =76 = 1
    • 24
      24 : 3 =24 : 24 = 같음 +1
      24 : 76 = 작음 +1
      
      24 = 2
    • [3, 76, 24] = [3, 1, 2]
profile
공부하자개발하자으쌰으쌰

0개의 댓글