분류 전체보기
-
TIL 자바 스프링부트 서버개발 올인원 : 30-32강Java 2024. 5. 8. 22:19
테이블을 만들 때 varchar(255)로 쓴 이유1. @Column의 기본값이 255이기 때문에 을 생략할 수 있게 된다.2. 문자열 필드는 최적화를 해야 하는 경우가 아닐 때 조금 여유롭게 설정하는 것이 좋다.(나중을 대비)Entity추가package com.group.libraryapp.domain.book;import javax.persistence.*;@Entitypublic class book { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id = null;// @Column(nullable = false, length = 255, name="name")// name = "name" DB의 이름..
-
인프런 워밍업 클럽/ BE 4일차 과제 : API 추가인프런 워밍업 클럽 2024. 5. 7. 20:06
이번 과제는 2일차 과제에 이어서 추가적인 API를 만들어 보는 것이다. 문제 1우선 Body로 넘어오는 Json 데이터를 받아주기 위해 DTO를 만들었다.Request Body를 사용해서 만들어준 DTO로 데이터를 받는다.sql문을 만들고 JdbcTemplate객체로 sql문 안에 ? 부분을 채워준다. 결과값5번째 사과가 추가 됐다! 📌Price에 int 대신 long을 사용한 이유는?int 타입은 4바이트로 -2,147,483,648 ~ 2,147,483,647 범위의 값을 표현할 수 있지만,long타입은 8바이트로 -9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807 표현할 수 있다.즉, 나중에 큰 값을 받을 것을 대비해서 long타입을 사용했다고 볼..
-
인프런 워밍업 클럽/ BE 3일차 과제 : 익명 클래스와 람다식인프런 워밍업 클럽 2024. 5. 1. 20:16
익명 클래스란 무엇인가?익명 클래스란 내부 클래스의 일종으로 이름 그대로 이름이 없는 클래스를 말한다.이름이 없다는 것은 앞으로 다시 사용하거나, 기억하지 않아도 된다는 의미로 일시적으로 사용되고 버려지는 클래스라고 할 수 있다. 일반적인 클래스 사용 경우// 부모 클래스class vehicle { public String getName() { return "탈 것"; }}// 자식 클래스class car extends vehicle { @Override public String getName() { return "자동차"; }}public class Main { public static void main(String[] args) { ve..
-
인프런 워밍업 클럽/ BE 2일차 과제 : API인프런 워밍업 클럽 2024. 4. 30. 15:39
문제1Controller@GetMapping("/api/v1/calc")public CalculatorResponseDTO getCalc(@RequestParam int num1, int num2){ return new CalculatorResponseDTO(num1, num2);}@GetMapping을 사용해서 API 주소를 설정해준다.쿼리파라미터를 받아주기 위해 @RequestParam을 사용해서 num1과 num2를 받아준다. 🚨주의 : 쿼리스트링으로 들어오는 변수이름과 @RequestParam으로 설정한 변수이름이 같아야 한다.더보기EX) /api/v1/calc?num1=2&num2=3 이라면 @RequestParam으로 받는 변수 이름도 num1과 num2로 정해야한다.만약 다른 이름으..
-
인프런 워밍업 클럽/ BE 1일차 과제 : 어노테이션인프런 워밍업 클럽 2024. 4. 29. 23:18
어노테이션을 사용하는 이유는 무엇일까?우선 어노테이션이란, 사전적의미로 주석이라는 뜻으로 소스코드에 추가해서 사용할 수 있는 메타 데이터의 일종이다. 메타 데이터란 애플리케이션이 처리해야할 데이터가 아니라 컴파일 과정에서 코드를 어떻게 처리해야하는지를 알려주기 위한 추가 정보이다.즉, 우리가 주석을 사용해서 다른 사람에게 추가적인 설명을 하는 것 처럼 코드에 어노테이션을 써서 프로그램에게 간결하고 쉽게 정보를 전달하게 된다. 그렇다면 왜 어노테이션의 역할은 무엇일까?컴파일러에게 코드 작성 문법 에러를 체크하도록 정보를 제공한다.소프트웨어 개발 툴이 빌드나 배치시 코드를 자동으로 생성할 수 있도록 정보를 제공한다.실행시 특정 기능을 실행하도록 정보를 제공한다.위와 같은 어노테이션의 역할로 코드의 가독성과 ..
-
DTO와 도메인을 분리해야 하는 이유프로젝트/게시판 2024. 4. 8. 23:12
게시판을 어느정도 만들고 JPA공부도 해보고싶어서 일단 친구에게 피드백을 받았다.(물론 아직 많이 남았는데,,JWT로그인 /게시물 CRUD/ 회원가입/ 페이징/ 검색 등 기초적인 부분만 끝났다.) 피드백 내용중 하나가 아래 내용이었다. 즉, 현재 계층마다 MemberDTO를 통해서 데이터를 전달하고 있는데 컨트롤러에서는 MemberSignUpRequest객체를 받고 서비스 계층에서 Member객체로 변환하는것이 좋다는 것이다. 이전에 RequestDTO / ResponseDTO를 나누는것이 좋다는 이야기를 들은적이 있는데 이번 기회로 좀 찾아보기로 했었다. 그렇게 유튜브를 뒤적거리는데 https://www.youtube.com/watch?v=OV8e88kIU-U&t=1s 해당 강의를 보게 되었고, 깨달음..
-
동시성 제어(Concurrency Control)CS 2024. 3. 26. 00:41
게시판을 만들다가 낙관적 락 이라는 단어를 주워 듣게 됐는데, 동시성 제어 기법 중 하나라는 것을 알게 되었다. 그래서 대충 알고 있었던 동시성 제어를 정리해봐야 겠다고 생각했다. 동시성 제어(Concurrency Control)란? 동시성 제어란 다수의 사용자로 인해 동시에 실행되는 여러개의 *트랜잭션 작업을 성공적으로 마칠 수 있도록 실행 순서를 제어하는 기법이다. *트랜잭션 DBMS에서 데이터를 다루는 논리적인 작업의 단위로 DB에서 여러 작업이 동시에 같은 데이터를 다룰 때가 이 작업을 서로 분리하는 단위가 된다. 트랜잭션은 전체가 수행되거나 또는 전혀 수행되지 않아야 한다.(All or Nothing) https://hsch19.tistory.com/13 @Transactional이란 무엇인가 ..
-
백준 1026번 : 보물 (JAVA)알고리즘, SQL/알고리즘 2024. 2. 13. 13:13
https://www.acmicpc.net/problem/1026 1026번: 보물 첫째 줄에 N이 주어진다. 둘째 줄에는 A에 있는 N개의 수가 순서대로 주어지고, 셋째 줄에는 B에 있는 수가 순서대로 주어진다. N은 50보다 작거나 같은 자연수이고, A와 B의 각 원소는 100보다 작거 www.acmicpc.net 지문에 A 배열은 정렬이 가능하지만, B배열은 정렬하지 말라는 조건이 있지만, 풀고나서 다른 사람들 풀이를 참고하니 다들 B배열까지 정렬하길래 풀이를 남겨본다. 풀이 방법 풀이방법으로는 A배열을 오름차순으로 정렬한 뒤, A배열의 가장 작은 값과 B배열의 가장 큰 값을 순서대로 찾도록 했다.(A배열의 가장 작은 값과 B배열의 가장 큰 값이 곱해지도록) 그리고 B배열에 같은 값이 중복해서 들어..