전체 글
-
RestTemplate Post Request - RestTemplate Hands On 4Spring Framework/RestTemplate 2023. 9. 24. 00:01
개요 이전 글에서는 RestTemplate을 활용하여 Get 요청의 QueryParam, PathVariable, Header등에 대해 학습했었습니다. 이번 글에서는 RestTemplate Post Request에 대해 학습해 보겠습니다. RestTemplate Post로 요청 보내기 @RestController class RestTemplatePostTestController { val baseUrl = "http://localhost:8080" @PostMapping("post-test") fun postTest() { val apiPath = "/post-test-call" val restTemplate = RestTemplate() val person = Person() val headers = ..
-
RestTemplate Get Request - RestTemplate Hands On 3Spring Framework/RestTemplate 2023. 9. 23. 00:01
개요 이전의 RestTemplate Get Request 파라미터 없는 요청에 대한 응답위주로 다루었다면 이번글은 QueryParam, PathVariable, Header 등 요청에 필요한 부가정보들을 어떻게 활용할 수 있는지 알아보고자 합니다. QueryParam 호출해보기 @GetMapping("/query-test-call") fun getQueryParamCall(@RequestParam param: Map): String { println(param) return "query" } Map으로 QueryParamater를 받는 api를 하나 준비했습니다. RestTemplate으로 queryParam 인자로 넘겨 호출하기 @GetMapping("/query-test") fun getQueryPa..
-
어느 날 고민 많은 주니어 개발자가 찾아왔다 2탄 - 김영한세미나, 영상 요약정리 2023. 9. 22. 00:01
https://www.inflearn.com/course/%EC%9D%B8%ED%94%84%EC%BD%982023-%EB%8B%A4%EC%8B%9C%EB%B3%B4%EA%B8%B0/dashboard [무료] 인프콘 2023 다시보기 - 인프런 | 강의 성장하는 IT인들의 축제, 인프콘 2023에서 진행된 오프닝 및 발표 세션을 영상으로 다시 보실 수 있습니다., ✅ 확인해주세요 이 콘텐츠는 2023년 8월 15일 화요일 진행된 인프콘 2023 다시보기 녹화 www.inflearn.com 2023 인프콘의 김영한 님의 발표를 듣고 요약해보고자 합니다. 김영한 님은 왜? 강의로 전향하게 되었을까? 주니어들이 학습을 하는데 시간이 많이 너무 들었다. 이유는 관련 자료들이 너무 쉽거나, 너무 복잡하거나 둘 중 ..
-
RestTemplate Get Request - RestTemplate Hands On 2Spring Framework/RestTemplate 2023. 9. 21. 00:01
개요 이전의 RestTemplate 생성과정에 이어 RestTemplate Get Request를 실습해보려 합니다. 글에서는 다음과 같은 테스트를 수행해 봅니다. Get으로 String 객체 호출해 보기 getForEntity와 getForObject의 차이점 String을 returnType으로 받지만 MyObject가 오는 경우 내가 원하는 필드만 발라내기 중첩 객체 필드도 받을 수 있는가 외부 호출 Controller 준비 @RestController class TestController { @GetMapping("/outer-call") fun outerCall(): String{ sleep(1000) return "process 1s job" } } // intellij HTTP plugin을..
-
RestTemplate이란? - RestTemplate Hands On 1Spring Framework/RestTemplate 2023. 9. 20. 00:01
개요 평소에 RestTemplate이란 기술을 알고 있었지만 FeignClient를 주로 활용하여 활용하곤 했습니다. 그러면 FeignClient를 더 학습하는게 좋을 텐데 굳이 RestTemplate을 학습하는 이유는 무엇일까요? 다른 개발자들은 Feign을 활용하는 대신 RestTemplate을 더 선호할 수 있습니다. RestTemplate을 활용하여 외부호출이 적용된 프로젝트들을 만날 수도 있습니다. RestTemplate을 활용하는 프로젝트를 만났기 때문에 이를 위해 공부해보고자 합니다. 이전에 FeignClient, WebClient, RestTemplate에 대해 비교하며 정리한글도 첨부해봅니다. RestTemplate이란? RestTemplate은 spring 3.0부터 등장한 기능입니다...
-
구독의 보너스 날짜 계산하기Java 2023. 9. 19. 00:01
개요 구독의 주기는 1달로 일어난다고 가정해 보겠습니다. 이때 만약 어떤 일로 인해서 미리 구독을 해지시키고 다시 1달짜리를 가입시켜 주어야 한다면 어떻게 될까요? 예를 들어 10월 15일에 어떤 사용자가 구독을 시작했는데 10월 21일에 구독 해지가 일어나고 다시 가입이 진행된다면 이 유저는 보너스 6일을 얻어야 합니다. 테스트 class BonusPeriodTest { @Test @DisplayName("현재 날짜가 10월15일이고, 구독일이 10월 1일이라면 해당 구독은 11월 1일에 만기되야하므로 보너스날짜는 17일이다") void test1(){ LocalDate currentDate = LocalDate.of(2023,10,15); LocalDate subscribedAt = LocalDate..
-
QueryDSL으로 페이징 구현하기JPA 2023. 9. 18. 00:01
개요 페이지네이션에 대해 알아보다 보면 상황에 따라 offset 기반과 cursor 기반의 방식으로 구현할 수 있습니다. 이때 offset 방식을 활용하여 QueryDSL으로 쿼리를 구현해보고자 합니다. Offset과 Limit 그리고 성능 SELECT * FROM TABLE_NAME LIMIT 10 OFFSET 5000; offset절은 만약 N이 들어온다면 N번째행부터 읽겠다는 의미입니다. 예를 들어 5000이라면 5000번째 행부터 읽겠다는 의미입니다. Limit 절은 쿼리 결과에서 지정된 순서에 위치한 레코드만 가져오고자 할 때 사용됩니다. Limit에는 클라이언트가 요청한 크기 N이 들어가게 되고 offset을 통해 가져온 전체 데이터에서 상위 N개를 가져옵니다. 위 둘을 조합하게 되면 5000..
-
QueryDSL으로 동적쿼리 작성하기JPA 2023. 9. 17. 00:01
개요 조회쿼리를 작성해야 하는데 다음과 같은 요구사항이 있었습니다. 날짜를 저장하는 A칼럼, B칼럼이 존재한다. "A칼럼 조회", "B칼럼 조회"와 같은 Client의 입력으로 A칼럼 또는 B칼럼에 대해 특정기간에 해당하는 Entity를 조회한다. 동적 조건에 따라 2가지 케이스를 쿼리해야 합니다. A칼럼 조회가 들어오면 where 절에 A필드를 특정기간에 조회하는 쿼리 B칼럼 조회가 들어오면 where 절에 B필드를 특정기간에 조회하는 쿼리 A칼럼 조회가 들어오면 where 절에 A필드를 특정기간에 조회하는 쿼리예시 select * from my_table WHERE A = BETWEEN 조회시작시간 AND 조회끝시간 B칼럼 조회가 들어오면 where 절에 B필드를 특정기간에 조회하는 쿼리 select..