분류 전체보기 225

[연습문제] 정수 제곱근 판별

[문제] 임의의 양의 정수 n에 대해, n이 어떤 양의 정수 x의 제곱인지 아닌지 판단하려 합니다. n이 양의 정수 x의 제곱이라면 x+1의 제곱을 리턴하고, n이 양의 정수 x의 제곱이 아니라면 -1을 리턴하는 함수를 완성하세요.제한 사항 n은 1이상, 50000000000000 이하인 양의 정수입니다. 입출력 예 n return 121 144 3 -1 입출력 예 설명 입출력 예#1 121은 양의 정수 11의 제곱이므로, (11+1)를 제곱한 144를 리턴합니다. 입출력 예#2 3은 양의 정수의 제곱이 아니므로, -1을 리턴합니다. [문제 풀이] public class 정수_제곱근_판별 { public long solution(long n) { long answer; int x = (int)Math.s..

[연습문제] 자릿수 더하기

[문제 설명] 자연수 N이 주어지면, N의 각 자릿수의 합을 구해서 return 하는 solution 함수를 만들어 주세요. 예를들어 N = 123이면 1 + 2 + 3 = 6을 return 하면 됩니다. 제한사항 N의 범위 : 100,000,000 이하의 자연수 예) N answer 123 6 987 24 입출력 예 설명 입출력 예 #1 문제의 예시와 같습니다. 입출력 예 #2 9 + 8 + 7 = 24이므로 24를 return 하면 됩니다. [문제풀이] import java.util.*; public class Solution { public int solution(int n) { int answer = 0; while(n > 0) { answer += n % 10; n /= 10; } // [실행]..

[연습문제] 평균 구하기

[문제] 문제 설명 정수를 담고 있는 배열 arr의 평균값을 return하는 함수, solution을 완성해보세요. 제한사항 arr은 길이 1 이상, 100 이하인 배열입니다. arr의 원소는 -10,000 이상 10,000 이하인 정수입니다. 입출력 예 arr return [1,2,3,4] 2.5 [5,5] 5 [문제풀이] class Solution { public double solution(int[] arr) { int a = arr.length; double sum = 0; for(int i=0; i

[연습문제] 짝수와 홀수

[문제] 문제 설명 정수 num이 짝수일 경우 "Even"을 반환하고 홀수인 경우 "Odd"를 반환하는 함수, solution을 완성해주세요. 제한 조건 num은 int 범위의 정수입니다. 0은 짝수입니다. 입출력 예 num return 3 "Odd" 4 "Even" [문제 풀이] 삼항 연산자를 이용하여 간단하게 해결 class Solution { public String solution(int num) { return (num%2==0) ? "Even" : "Odd" ; } }

[SELECT] 여러 기준으로 정렬하기

문제 ANIMAL_INS 테이블은 동물 보호소에 들어온 동물의 정보를 담은 테이블입니다. ANIMAL_INS 테이블 구조는 다음과 같으며, ANIMAL_ID, ANIMAL_TYPE, DATETIME, INTAKE_CONDITION, NAME, SEX_UPON_INTAKE는 각각 동물의 아이디, 생물 종, 보호 시작일, 보호 시작 시 상태, 이름, 성별 및 중성화 여부를 나타냅니다. NAME TYPE NULLABLE ANIMAL_ID VARCHAR(N) FALSE ANIMAL_TYPE VARCHAR(N) FALSE DATETIME DATETIME FALSE INTAKE_CONDITION VARCHAR(N) FALSE NAME VARCHAR(N) TRUE SEX_UPON_INTAKE VARCHAR(N) FA..

게시글 조회하기

※ 게시글의 번호를 이용하여 게시글을 조회할 수 있다. 1. Controller @GetMapping({"/read"}) public void read(long sno, @ModelAttribute("requestDTO") PageRequestDTO requestDTO, Model model, @AuthenticationPrincipal PrincipalDetail principalDetail) { Long principalMno = principalDetail.getMno(); StadiumDTO stadiumDTO = landersService.getStadium(sno, principalDetail); model.addAttribute("dto", stadiumDTO); } Get 방식으로 URL을..

BACK-END/Springboot 2022.09.26

[Spring Security] 로그인

Spring Security 설정을 위한 SecurityConfig.java를 생성한다. # 코드 전문 @EnableWebSecurity @EnableGlobalMethodSecurity(prePostEnabled = true) // 특정 주소 접근 시 권한/인증 체크 public class SecurityConfig extends WebSecurityConfigurerAdapter { @Override public void configure(WebSecurity web) throws Exception { web.ignoring().antMatchers("/css/**", "/js/**", "/assets/**", "/font/**", "/stadiumImg/**"); } @Override protect..

[Spring Security] 회원가입

[핵심 내용] BCryptPasswordEncoder 클래스 [※ 참고: https://kimvampa.tistory.com/129] 1. 저장할 Member의 정보를 담을 객체를 생성한다. @Data public class MemberDTO { private Long mno; private String username; private String name; private String password; private LocalDateTime regDate; // 등록일 private LocalDateTime modDate; // 수정일 } 이 때, 등록일과 수정일은 자동으로 입력된다. 2. 가입 프로세스를 위한 Controller, Service을 작성한다. // Controller @PostMappin..

Parameter 0 of constructor in [SecurityConfig] required a bean of type [PrincipalDetailService] that could not be found.

[ERROR Message] Parameter 0 of constructor in com.bbgo.config.SecurityConfig required a bean of type 'com.bbgo.config.PrincipalDetailService' that could not be found. Action: Consider defining a bean of type 'com.bbgo.config.PrincipalDetaailService' in your confniguration. [해결 방법] PrincipalDetailService에 @Service 어노테이션을 누락해서 발생한 에러였다. @Service 어노테이션을 추가하여 에러 수정 완료.

Error Report 2022.08.25

Error creating bean with name 'springSecurityFilterChain' defined in class path resource

[ERROR Message] org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'springSecurityFilterChain' defined in class path resource [org/springframework/security/config/annotation/web/configuration/WebSecurityConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instant..

Error Report 2022.08.25