2023.07.18.화.TIL

heeh·2023년 7월 19일

TIL

목록 보기
45/82
post-thumbnail

2023.07.18.화

public ProfileUpdateDto detailProfile (UserDetailsImpl userDetails) {
        ProfileUpdateDto profileUpdateDto = new ProfileUpdateDto(userDetails.getUser());
        return profileUpdateDto;
    }
  • 생성자와 파라미터 넣어주는 부분 확인하기!
  • getUser를 위와 같이 갖고 올 수도,
    → ProfileUpdateDto에서 생성자에 user를 파라미터로 같이 불러와서 get으로 불러옴
  • 아니면 Service의 코드에서
    → User user = userDetails.getUser();
  • .requestMatchers("/api/**").permitAll()
    • api로 시작하는 모든 것을 인증을 하지 않고 실행하겠다
  • 프로젝트 전역적으로 사용하는 것은 common
  • @Controller → @ResponseBody 디티오로 반환
  • @RestController → 그냥 디티오로 반환이됨
  • @Configuration
    • Bean으로 저장될 때 -> passwordConfig
  • .equals()는 두 문자열의 내용을 비교, .matches()는 문자열이 정규 표현식 패턴과 일치하는지 확인
    • .equals()
      • 두 개의 문자열을 비교하여 값이 동일한지 확인
      • String 클래스에서 상속된 메서드이며, 객체 간의 내용 비교에 사용
      • "abc".equals("abc")true를 반환하고, "abc".equals("def")false를 반환
    • .matches()
      • 정규 표현식을 사용하여 문자열을 패턴과 비교
      • String 클래스에는 없는 메서드이지만, Pattern 클래스에서 제공
      • "abc".matches("[a-z]+")true를 반환하고, "123".matches("[a-z]+")false를 반환
    • 비밀번호가 소문자 영어와 숫자, 특수문자를 포함하는데 알파벳만 true??
  • requestDto.setPassword(passwordEncoder.encode(requestDto.getPassword()));
    • 비밀번호를 암호화하여 requestDto의 비밀번호 필드에 설정하는 코드
    • passwordEncoder는 주어진 비밀번호를 암호화하는 데 사용되는 객체로 가정
    • requestDto.getPassword()requestDto 객체에서 비밀번호를 가져오는 메서드로 가정
    • passwordEncoder.encode()는 주어진 비밀번호를 암호화하는 메서드로, 암호화된 비밀번호를 반환
    • 이 암호화된 비밀번호는 requestDto.setPassword()를 통해 requestDto 객체의 비밀번호 필드에 설정
    • 암호화된 비밀번호는 일반 텍스트로 저장되는 대신, 보안상 안전한 형태로 저장되어 보안 강화에 도움
  • 메서드 사용을 왜 못하는데 Entity User의
    public void updateProfile(ProfileUpdateDto profileUpdateDto) {
        this.userEmail = profileUpdateDto.getUserEmail();
        this.userPassword = profileUpdateDto.getUserPassword();
        this.userNick = profileUpdateDto.getUserNick();
        this.myContent = profileUpdateDto.getMyContent();
    }
    는 UserService의 public ProfileUpdateDto updateProfile에
    User user = userDetails.getUser();
    
            user.setUserEmail(profileUpdateDto.getUserEmail());
            user.setUserPassword(profileUpdateDto.getUserPassword());
            user.setUserNick(profileUpdateDto.getUserNick());
            user.setMyContent(profileUpdateDto.getMyContent());
    로 적어줄 수 있지만왤케 길까.. 왜 User의 updateProfile 메서드가 no usages 일까... 흑흑..UserService의 public ProfileUpdateDto updateProfile의 updateProfile를 메서드로 해줬다고 착각했구user.updateProfile(profileUpdateDto); 로 메서드를 불러와줬습니다() 안의 내용은 같이 실행되면서 업데이트 되어야 할 원래의 내용이 담긴 클래스! 하여
    				user.setUserEmail(profileUpdateDto.getUserEmail());
            user.setUserPassword(profileUpdateDto.getUserPassword());
            user.setUserNick(profileUpdateDto.getUserNick());
            user.setMyContent(profileUpdateDto.getMyContent());
    user.updateProfile(profileUpdateDto);
    의 역할과 같다updateProfile 안에 들어있는 것들이니까!차이점은 따로따로 갖고 오느냐, 메서드로 통째로 갖고 오느냐임니다! User user = userDetails.getUser();는 user는 로그인 유저를 대입 받고 (풀어서 쓰든 메서드로 쓰든 꼭 필요!!) user.updateProfile(profileUpdateDto);user는 프로필을 업데이트 해줄 수 잇따
profile
공부하자개발하자으쌰으쌰

1개의 댓글

comment-user-thumbnail
2023년 7월 19일

유익한 글 잘 봤습니다, 감사합니다.

답글 달기