일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 |
- 보안 #이슈
- 스파르타코딩클럽 #부트캠프 #IT #백엔드 #머신러닝 #AI #서버 #자동화 #SQL #기본문법 #데이터베이스
- ci/cd파이프라인
- 스파르타코딩클럽 #부트캠프 #IT #백엔드 #머신러닝 #AI #서버 #자동화 #SQL #기본문법 #데이터베이스 #웹개발
- 스파르타 코딩클럽 #내배캠 #모의면접 #예상질문 #http 메서드 종류 #메서드 #post #put #get #patch #springmvc패턴 #model #view #controller
- 프로세스 #CPU #시공유 #커널
- 스파르타 코딩클럽 #내배캠 #최종프로젝트 #로그인 #인증인가 #jwt? #토큰인증 #액세스토큰 #리프레시토큰 #쿠키 #파싱 #서명키의 중요성 #security context holder
- 인가 #
- 스파르타 코딩클럽 #내배캠 #모의면접 #예상질문 #http 메서드 종류 #메서드 #post #put #get #patch #최종프로젝트 #aws s3 #프로필 이미지 수정 #자동삭제
- 스프링 #백엔드 #자바
- 스파르타 코딩클럽 #내배캠 #모의면접 #예상질문 #http 메서드 종류 #메서드 #post #put #get #patch #tdd #테스트 주도개발 #테스트코드 #유닛테스트
- java5기
- 공간복잡도 #공간자원 #캐시메모리 #SRAM #DRAM #시간복잡도
- 스파르타 코딩클럽 #내배캠 #모의면접 #예상질문 #http 메서드 종류 #메서드 #post #put #get #patch #트랜잭션전파 #transaction
- 비트 #바이트 #이진수
- 스파르타코딩클럽 #부트캠프 #IT #백엔드 #머신러닝 #딥러닝 #AI #서버 #자동화 #SQL #기본문법 #데이터베이스 #DBMS #Oracle #MongoDB #아키텍쳐 #DB
- 스파르타 코딩클럽 #인메모리db #h2 #연동이슈 #문제해결 #방법 #spring security #header #
- 스파르타코딩클럽 #부트캠프 #IT #백엔드 #OSI #ISO #AI #서버 #자동화 #SQL #기본문법 #데이터베이스 #DBMS #Oracle #MongoDB #아키텍쳐 #DB
- 스파르타 코딩클럽 #내배캠 #모의면접 #예상질문 #http 메서드 종류 #메서드 #post #put #get #patch #ci #cd
- 스파르타 코딩클럽 #내배캠 #최종프로젝트 #4개월삭제 #국비지원 #자바
- spring security #jwt 토큰 #json web token #token #직렬화 #인증
- 스파르타 코딩클럽 #내배캠 #모의면접 #예상질문 #http 메서드 종류 #메서드 #post #put #get #patch #ci #ioc #의존성
- 쓰레드 #쓰레드풀 #프로세스
- 스파르타코딩클럽 #부트캠프 #IT #백엔드 #머신러닝 #딥러닝 #AI #서버 #자동화 #SQL #기본문법 #데이터베이스
- 스파르타 코딩클럽 #내배캠 #모의면접 #예상질문 #http 메서드 종류 #메서드 #post #put #get #patch #aop #관점지향프로그래밍 #유지보수
- 스파르타코딩클럽 #부트캠프 #IT #백엔드 #머신러닝 #AI #서버 #자동화 #SQL #KDT #기본문법 #데이터베이스 #Computer #Science #CPU #메모리
- 챌린저스 #bod
- 스파르타 코딩클럽 #내배캠 #모의면접 #예상질문 #http 메서드 종류 #메서드 #post #put #get #patch #소셜로그인 #네이버 #기능구현 #vue.js #spring boot #네이버로그인 #연동하기
- 스파르타 코딩클럽 #내배캠 #모의면접 #예상질문 #http 메서드 종류 #메서드 #post #put #get #patch #get방식 #post방식 #http프로토콜 #클라이언트 #백엔드 #api
- 스파르타 코딩클럽 #내배캠 #모의면접 #예상질문 #http 메서드 종류 #메서드 #post #put #get #patch #대용량트래픽 #처리방법 #캐싱 #코드최적화 #db최적화 #트래픽 #로드밸런서
- Today
- Total
요리사에서 IT개발자로
스파르타 부트캠프 스프링 부트 프로젝트 생성 및 CR (다락방) 본문
build.gradle
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-web'
compileOnly 'org.projectlombok:lombok'
runtimeOnly 'com.mysql:mysql-connector-j'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
}
validation -> 사용자 관점에서 시스템 검증 활동을 의미한다.
@Valid
Controller안의 로직 중 인풋값에 @Valid를 설정하면
제공된 라이브러리 로직 중 해당 로직이 검증을 하고 수행한다.
검증을 더 자세히 해준다.
https://tech-sherpa.tistory.com/12
Jpa(Java Persistence API)
자바진영에서
ORM(Object-Relational Mapping) 기술 표준으로 사용되는 인터페이스 모음
Web
웹으로 API를 호출하기 위해 사용되는 Http Client 모듈
https://happycloud-lee.tistory.com/220
Lombok
기계적인 코드작성을 자동화 하여
코드 다이어트를 해주는 Java 필수 라이브러리
@Getter @Setter 등등
https://mangkyu.tistory.com/78
application.properties
spring.application.name=SettingProject
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/db_services
spring.datasource.username=이름
spring.datasource.password=비밀번호
spring.jpa.database=mysql
spring.jpa.database-platform=org.hibernate.dialect.MySQL8Dialect
spring.jpa.hibernate.ddl-auto=update
spring.jpa.generate-ddl=false
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true
MySQL의 데이터 베이스 연동을 하기위해
name, url, username, password 는 기본으로 설정
spring.jpa.database
사용하는 데이터 베이스 종류를 입력
spring.jpa.hibernate.ddl-auto
none:
기본값, 데이터베이스 구조 변경x
update
Hibernate 주어진 엔티티 구조에 따라 데이터베이스를 변경
create
데이터베이스를 생성은 하되 닫을 때 삭제하지 않는다.
create-drop
데이터베이스를 생성하고 SessionFactory가 닫힐 때 삭제. 생성하고 서버닫으면 삭제
spring.jpa.generate-ddl
- 시작시 스키마를 초기화할 지 여부
spring.jpa.database-platform
- MySQL은 org.hibernate.dialect.MySQL8Dialect
- PostgreSQL은 org.hibernate.dialect.PostgreSQLDialect
spring.jpa.properties.hibernate.format_aql:
- log가 console에 SQL문을 출력한다.
spring.jpa.hibernate.jdbc.time_zone
- @createdAt,@updatedAt 타임 스탬프 시간을 설정한다.
spring.jpa.properties.hibernate.jdbc.time_zone=UTC
https://chung-develop.tistory.com/143
https://pcm9881.tistory.com/130
Create
생성하려면 Entity가 필요하고
public class Card {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String number;
Client에게 요청 로직 (Request)받을 Dto를 생성하고
public class CardReqeustDto {
private String number;
}
Controller에서 Url에 접근 하게 해주고
@PostMapping("/cards")
public ResponseEntity<Card> createCard(@RequestBody CardReqeustDto cardRequestDto) {
Card createdCard = cardService.createCard(cardRequestDto);
return ResponseEntity.status(HttpStatus.CREATED).body(createdCard);
}
caredService의 createCard로 접근하여
Service에서 로직을 구현해주고
public Card createCard(CardReqeustDto cardRequestDto) {
String number = cardRequestDto.getNumber();
Card card = new Card(number);
return cardRepository.save(card);
}
caredRequestDto의 요청을 저장할 number를
Card card = new Card(number) 저장할 수 있는
Card Entity에서 생성자를 선언
public Card(String number) {
this.number = number;
}
이제 cardRepository에 save 메소드를 사용하여 card를 저장
public interface CardRepository extends JpaRepository<Card, Long> {
}
return
return ResponseEntity.status(HttpStatus.CREATED).body(createdCard);
Read
@PathVariable
url에 id를 입력하면
controller를 타고
@GetMapping("/cards/{id}")
public ResponseEntity<CardResponseDto> getCardById(@PathVariable Long id) {
CardResponseDto cardResponseDto = cardService.getCardById(id);
return ResponseEntity.ok().body(cardResponseDto);
}
getCardByID에 id는
cardRepository의 findById(id) 를 넣고
.map을 사용하여 CardResponseDto를 생성 및 선언에 입력값을 넣고 저장 후
optionalCard에 다시 입력
그렇게 보내지고
public CardResponseDto getCardById(Long id) {
Optional<Card> optionalCard = cardRepository.findById(id);
return optionalCard.map(CardResponseDto::new).orElse(null);
}
return 하게된다.
return ResponseEntity.ok().body(cardResponseDto);
중요
ResponseEntity<List<CardResponseDto>>
로 클래스를 설정하면
List<CardResponseDto> cardResponseDtos
ReponseEntity는
return ResponseEntity.ok().body(cardResponseDtos);
이렇게 List<CardResponseDto> 형식만 가능하다.
'Spring' 카테고리의 다른 글
스파르타 부트캠프 REST API 요청과 응답 (다락방) (0) | 2024.06.14 |
---|---|
스파르타 부트캠프 스프링 부트 U(update)D(delete) 다락방 (3) | 2024.06.13 |
스프링 시큐리티 내부 구조 Security Filter Chain 등록, 여러개 등록, 특정 요청 허가 (1) | 2024.06.11 |
Spring Security 내부 구조 DelegatingFilterProxy와 FilterChainProxy (0) | 2024.06.11 |
Spring Boot PostMan사용, JWT 인증,인가 (로그인, 로그아웃, 회원탈퇴) (1) | 2024.06.10 |