공부 기록들

    알고리즘 모아보기

    알고리즘 모아보기 최대공약수 GCD(Grateast Common Divisor) // 재귀 public long gcd(int w, int h) { if (h == 0) { return w; } return gcd(h, w % h); } // 반복문 public static long gcd2(int w, int h) { int n; if (w < h) { int temp = w; w=h; h = temp; } while (h != 0) { n = w % h; w=h; h = n; } return w; } 최소공배수 LCM(Least Common Multiple) (각 숫자 / 최대공약수) * 최대공약수 // 두 개만 비교할 때에 두 수의 곱 / 최대공약수가 최소공배수가 됨 순열과 조합(Permutatio..

    기타 등등(계속 추가)

    기타 등등 (계속 추가) 당연히 알고있다 생각하지만 흐릿하거나 모르고 지나칠 수 있는 상식들을 적어 두었다. 000001. static 인스턴스를 생성하면 서로 다른 값을 유지하기 때문에 경우에 따라서 각 인스턴스들이 공통적으로 같은 값이 유지되어야 하는 경우 static을 붙인다. static이 붙은 멤버변수(클래스 변수)는 클래스가 메모리에 올라갈 때 이미 자동적으로 생성되기 때문에 인스턴스를 생성하지 않아도 사용할 수 있다. static이 붙은 메서드에서는 인스턴스 변수를 사용할 수 없다. 반대는 가능하다. 메서드의 작업 중에서 인스턴스 변수를 필요로 한다면, static을 붙일 수 없지만 만약 필요로 하지 않는다면 static을 붙여서 메서드 호출시간을 짧게해줄 수가 있다. static 영역은 G..

    Spring Configuration 기초 정리

    Spring Configuration 기초 정리 @Configuration과 @Bean class JavaConfigTest { @Test void javaConfig() { ApplicationContext context = new AnnotationConfigApplicationContext(HelloApplication.class); String[] beanDefinitionNames = context.getBeanDefinitionNames(); System.out.println(Arrays.toString(beanDefinitionNames)); AuthService authService = context.getBean(AuthService.class); assertThat(authService..

    Spring Auth 기초 정리

    Spring Auth 기초 정리 세션이란? 세션이란 클라이언트 별로 서버에 저장되는 정보다. 웹 클라이언트가 서버측에 요청을 보내게 되면 서버는 클라이언트를 식별하는 session id를 생성한다. 서버는 session id를 이용해서 key와 value를 이용한 저장소인 HttpSession을 생성한다. 서버는 session id를 저장하고 있는 쿠키를 생성하여 클라이언트에 전송한다. 클라이언트는 서버측에 요청을 보낼 때 session id를 가지고 있는 쿠키를 전송한다. 서버는 쿠키에 있는 session id를 이용해서 그 전 요청에서 생성한 HttpSession을 찾고 사용한다. 세션을 얻기 위해서는 request로 부터 getSession() 메서드를 호출해야 하지만, 스프링은 알아서 얻어와주기 ..

    Spring MVC Config 기초 정리

    Spring MVC Config 기초 정리 addViewControllers /** * 사용자가 "/"로 요청을 보냈을 때 hello.html이 응답되어야 함 * * WebMvcConfiguration의 addViewControllers 메서드로 설정하기 */ @Test void addViewControllers() { // when ExtractableResponse response = RestAssured .given().log().all() .when().get("/") .then().log().all().extract(); // then Assertions.assertThat(response.statusCode()).isEqualTo(HttpStatus.OK.value()); } @Configur..

    Spring CORE 기초 정리

    Spring CORE 기초 정리 @Component public class LineDao { } @Component가 붙으면 해당 클래스를 빈 등록해준다는 뜻이다. @Controller, @Service, @Repository 어노테이션 내부에는 모두 @Component를 포함하고 있다. @ComponentScan은 @Component가 붙은 클래스들을 읽어들여 빈 등록을 해준다. 보통 main 함수를 가지고 있는 클래스 위에 @SpringBootApplication를 달고있는데, 해당 어노테이션 내부에 @ComponentScan이 존재한다. 현재 디렉토리 위치에서부터 아래로 내려가면서 스캔을 하기 때문에 보통 @ComponentScan의 위치가 최상단에 존재하는 이유가 바로 이것이다. 의존관계 주입 방..

    Spring JDBC 기초 사용법 정리

    Spring JDBC 기초 사용법 정리 NamedParameterJdbcTemplate @Repository public class NamedParamDAO { private NamedParameterJdbcTemplate namedParameterJdbcTemplate; public NamedParamDAO(NamedParameterJdbcTemplate namedParameterJdbcTemplate) { this.namedParameterJdbcTemplate = namedParameterJdbcTemplate; } /** * MapSqlParameterSource * public T queryForObject(String sql, SqlParameterSource paramSource, Class..

    Spring MVC 기초 정리

    Spring MVC 기초 정리 매핑 요청 @RestController @RequestMapping("/http-method") public class HttpMethodController { @PostMapping("/users") public ResponseEntity createUser(@RequestBody User user) { Long id = 1L; return ResponseEntity.created(URI.create("/users/" + id)).build(); } @GetMapping("/users") public ResponseEntity showUser() { List users = Arrays.asList( new User("이름", "email"), new User("이름", "..