전체 글
-
[스프링] 사용자 IP를 추적하는 방법스프링(Spring) 2023. 7. 22. 22:14
특정 글을 작성한 사용자의 IP는 어떻게 추적하는 걸까 의문이 들었다. 이에 대한 여러 방법이 있겠지만 스프링을 사용해야하는 나로서는 우선 스프링을 기준으로 조사해보기로 결정했다. 가장 간편하게 Chat GPT에게 질문했다. 게시판 사이트를 만들 때 게시글을 수정했거나 등록한 사용자의 ip를 추적해 MySQL에 기록하려고 해. 스프링을 사용할 예정인데 이럴 때는 어떻게 ip 추적을 구현할 수 있을까? GPT는 다음과 같은 코드를 예시로 들어줬다. import org.springframework.web.bind.annotation.*; import javax.servlet.http.HttpServletRequest; @RestController public class BoardController { @Po..
-
외래키(foreign key)를 쓰지 않는 이유DB 2023. 7. 22. 01:07
오늘 일을 하며 DB를 짜던 도중 외래키를 쓰지 않는 것이 좋다는 선임분의 말을 들었다. 이때까지 식별관계, 비식별관계 따져가며 테이블과 테이블 간의 접점을 위해 외래키를 잘 설정해주려고 노력했는데 왜인지 의아했다. 하지만 실제로 외래키를 설정하게 되면 제약사항이 많아져서 그렇다고 한다. 가령 cascade 설정으로 인해 A테이블을 삭제하면 B테이블이 삭제되거나, A를 수정하기 위해선 B까지 수정해야하는 경우들이 있다. 외래키에 대한 이해를 위해 간단한 예시를 첨부했다. 수강하는 주체인 학생과 그 대상인 강의, 그리고 그 행위를 나타내는 등록이 있다. 누가 어떤 강의를 듣는지 알기 위해 위와 같이 외래키로 테이블들을 이어주었다. 참고로 이들은 식별관계이다 cf) 식별관계: 어떤 테이블 (Student와 ..
-
varchar와 nvarchar의 차이DB 2023. 7. 21. 00:45
다양한 길이의 글자를 저장하는 데이터 타입, 유니코드를 지원하지 않는다. 그래서 영문, 숫자 또는 데이터베이스의 기본언어로 설정된 것에 대해서는 1바이트, 그 외의 언어에는 글자당 2바이트가 사용된다. 최대 길이(max): 지정하지 않으면 기본값 1이다. 255 bytes를 초과할 수 없다. => MySQL 기준 5.0.3 이후 최대 값은 65535bytes이다. 최소 길이(reserve): 지정하지 않으면 기본 값은 0 이다. 범위는 0 - 최대 값 이다. 공백까지 그대로 저장한다. varchar(max, reserve) Plus) 255바이트까지는 길이에 대한 정보를 담는 것에 1바이트가 쓰이지만 255바이트를 초과하면 길이 정보에 2바이트가 쓰인다. 쉽게 말해, 254바이트 만큼의 텍스트를 쓴다고 ..
-
템플릿 메서드 패턴 and 팩토리 메서드 패턴CS 2023. 6. 25. 17:48
전체적인 코드의 구조를 정하는 템플릿 메서드를 구현하고 자주 변경되는 부분은 분리하여 하위 클래스에서 구현 및 수정이 가능하도록 하는 패턴 상위 클래스에서 공통적으로 필요한 부분, 변하지 않는 부분은 정의해두어 기본적인 코드 알고리즘의 골격과 흐름은 짜여진 상태, 그 구조 내 사용되는 메서드 중에는 훅 메소드(디폴트 값이 정해져있어 그대로 사용해도 되고 추후 수정해도 되는 것) 또는 추상 메서드(메서드 이름 앞에 abstract를 붙이며 하위 클래스에서 반드시 오버라이딩 후 구현해야하는 메서드)가 들어있다. 이처럼 코드의 구조가 잡혀 있는 메서드를 템플릿 메서드라고 한다. (마치 찍어내는 템플릿 같다.) 이 패턴의 경우 코드의 구조를 보호하고 중복을 최소화하기 위한 용도로 사용하는 것 같다. 객체 생성에..
-
Docker, Elasticbeanstalk, Travis CI항해 99 2022. 8. 23. 00:59
프로젝트에서 도커와 AWS, CI/CD를 통한 배포 프로세스는 다음과 같다. 깃헙으로 push -> Travis CI가 이를 인식 -> 테스트 코드 실행 후 테스트 통과 시 운영환경의 이미지 빌드 -> 빌드된 이미지가 Dockerhub로 전달됨 -> Dockerhub 내 새로운 이미지가 생겼다고 AWS EB에 전달 -> AWS EB가 해당 이미지를 가져와서 ec2에 배포를 진행 Docker 먼저 실전 프로젝트에서 사용된 Docker 파일을 살펴보자. 아래는 개발 환경용인 Dockerfile.dev이다. # 노드를 베이스로 생성 FROM node:16.13.1 # app 디렉토리 , working 디렉토리 생성 RUN npm install -g nodemon # -g = global RUN mkdir -p..
-
백준 1002번 터렛알고리즘 2022. 6. 2. 18:34
출처 링크: https://www.acmicpc.net/problem/1002 열심히 경우를 고려하였지만 쉽지 않았다. /* r의 위치와의 관계 1) x좌표는 같고 y좌표만 차이나는 경우 2) y좌표는 같고 x좌표만 차이나는 경우 일직선상에 있는지 아닌지 판별 필요 3) x, y 좌표 둘 다 차이나는 경우 => 피타고라스 정리 활용 a**2 + B**2 = c**2 */ // 0 0 13 40 0 37 const x1 = 0 const y1 = 0 const r1 = 13 // 류재명과의 거리 const x2 = 40 const y2 = 0 const r2 = 37 // 류재명과의 거리 if (y1 === y2) { // 일직선상에 있는지 판단 // 일직선상에 있다면 y좌표가 똑같을 것 // 일직선상에 ..
-
백준 1011번 Fly me to the Alpha Centauri알고리즘 2022. 5. 29. 23:33
출처 링크: https://www.acmicpc.net/problem/1011 나의 풀이 let x = 45 let y = 50 /* 처음 시작은 무조건 1, 그 다음은 점점올라가다가 떨어지는 대칭 형태의 그래프에 가까움, 그래야 마지막에 y에 도달하기 전에는 1만큼 이동할 것이기 때문 => 그럼 그 중간 지점이 되는 부분을 어떻게 찾지? 1) 일단 3 < y-x 인지 아닌지로 나눠보자 0 { if (!(3 < b - a)) { // 이 경우 둘의 차이 만큼이 답이 된다. return b - a } else { /* b - a가 4일때 1 2 1 총 3번 5일때 1 2 1 1 총 4번 6일때 1 2 2 1 총 4번 7일때 1 2 2 1 1 총 5번 8일때 1 2 2 2 1 총 5번 9일때 1 2 3 2 ..
-
백준 1110번 더하기 사이클알고리즘 2022. 5. 23. 21:54
출처 링크: https://www.acmicpc.net/problem/1110 나만의 풀이법 // 입력값 const n = 26 let num = n let result = 0 let cycle = 0 while (true) { // 10 보다 작은 경우 앞 자리에 0 붙여서 연산하기 if (num < 10) { // result = 0 + num 이므로 아래와 같이 식을 써주어도 상관없다. num = Number(`${num}` + `${num}`) } else { result = `${num}`[0]/1 + `${num}`[1]/1 num = Number(`${num}`[1] + `${result}`.split('').pop()) // 이처럼 result를 문자열로 바꾼 후 split하면 result..