반응형

분류 전체보기 87

리액트에서 API 호출 URL을 환경 변수로 설정하자

왜 API URL을 환경 변수로 설정해야 하지?프론트단과 서버단의 동시 작업을 위해서이다. 서버단의 개발이 완벽하여 서버 애플리케이션을 도커로 띄워놓고 해당 버전에 맞게만 리액트 애플리케이션을 개발해도 된다면 문제가 없지만, 실제로는 프론트단과 서버단의 개발이 동시에 진행될 것이고, 개발환경과 운영환경의 API URL은 달라질 수밖에 없다.커밋할 때마다 API를 호출하는 메서드별로 URL을 수정하는 것은 사실상 불가능에 가깝다. 어떻게 해?먼저 환경 변수 파일을 작성한다.해당 환경 변수 파일을 전역 변수로 사용할 수 있도록 자바스크립트 파일을 작성한다.API를 호출하는 파일에 import 하여 해당 환경 변수를 URL에 주입한다. 예제를 살펴보자 .env# 개발환경# REACT_APP_API_BASE_U..

개발/리액트 2025.02.23

[LeetCode] 26. Remove Duplicates from Sorted Array #Easy #Java

문제Given an integer array nums sorted in non-decreasing order, remove the duplicates in-place such that each unique element appears only once. The relative order of the elements should be kept the same. Then return the number of unique elements in nums. Consider the number of unique elements of nums to be k, to get accepted, you need to do the following things: Change the array nums such that the..

[LeetCode] 21. Merge Two Sorted Lists #Easy #Java

문제You are given the heads of two sorted linked lists list1 and list2.Merge the two lists into one sorted list. The list should be made by splicing together the nodes of the first two lists.Return the head of the merged linked list.예제 1Input: list1 = [1,2,4], list2 = [1,3,4]Output: [1,1,2,3,4,4]예제 2Input: list1 = [], list2 = []Output: []예제 3Input: list1 = [], list2 = [0]Output: [0]제약조건✅ The numbe..

[LeetCode] 14. Longest Common Prefix #Easy #Java

문제Write a function to find the longest common prefix string amongst an array of strings.If there is no common prefix, return an empty string "".예제 1Input: strs = ["flower","flow","flight"]Output: "fl"예제 2Input: strs = ["dog","racecar","car"]Output: ""// Explanation: There is no common prefix among the input strings. 제약조건✅ 1 ✅ 0 ✅ strs[i] consists of only lowercase English letters if it is non-..

[LeetCode] 9. Palindrome Number #Easy #Java

문제Given an integer x, return true if x is a palindrome, and false otherwise.예제 1Input: x = 121Output: true// Explanation: 121 reads as 121 from left to right and from right to left.예제2Input: x = -121Output: false// Explanation: From left to right, it reads -121. From right to left, it becomes 121-. Therefore it is not a palindrome.예제3Input: x = 10Output: false// Explanation: Reads 01 from right ..

QueryDSL을 사용해보자

QueryDSL이 뭐야? 자바 및 코틀린에서 객체지향적으로 SQL / JPQL 쿼리를 작성할 수 있도록 돕는 쿼리 빌더 라이브러리다.작성자는 동적 쿼리를 처리하기 위해 QueryDSL을 도입했다. 가령 공지사항에서 게시물을 조회할 때 사용자는 제목 조건을 포함하여 조회할 수도 있고, 포함하지 않을 수도 있다.이러한 상황을 처리하기 위한 것이 동적 쿼리이다.JPA에서도 Criteria API를 제공하여 동적 쿼리를 처리할 수 있게 하지만 문법이 굉장히 복잡하다.코드 유지보수성도 개발에 있어 굉장히 중요하기 때문에 다른 방안이 필요했다. SQL Mapper Framework MyBatis를 통해 동적 쿼리를 처리할 수도 있다.현업에서는 아마 MyBatis를 더 많이 쓸 것이다.그 이유로는 직접 SQL을 작성..

개발/스프링 2025.02.15