Skip to Content
처음부터 제대로 배우는 스프링 부트
book

처음부터 제대로 배우는 스프링 부트

by 마크 헤클러, 오시영, 서정대
May 2023
Beginner to intermediate
384 pages
8h 42m
Korean
Hanbit Media, Inc.
Content preview from 처음부터 제대로 배우는 스프링 부트
83
4
데이터베이스 액세스
}
}
손볼 만한 또 다른 부분은
putCoffee ()
메서드의 삼항 연산자 불 조건입니다.
repository
사용하도록 메서드를 리팩터링한 후에는 부정 조건을 먼저 평가할 이유가 없습니다. 조건에서
NOT
(!) 논리 연산자를 제거해 코드 가독성을 높입니다. 그러고 나서 원래 결과를 유지하기
위해 다음 코드처럼 삼항 연산자의 참과 거짓 값을 바꿔줍니다.
@PutMapping("/{id}")
ResponseEntity<Coffee> putCoffee(@PathVariable String id,
@RequestBody Coffee coffee) {
return (coffeeRepository.existsById(id))
? new ResponseEntity<>(coffeeRepository.save(coffee),
HttpStatus.OK)
: new ResponseEntity<>(coffeeRepository.save(coffee),
HttpStatus.CREATED);
}
TIP
_
코드 사용하기
완성된 코드는 깃허브(
chapter4end
브랜치)에서 확인할 수 있습니다.
4.5
마치며
앞 장에서 만든 스프링 부트 애플리케이션에
DB
액세스를 추가하는 방법을 다루었습니다. 그
리고 스프링 부트의 데이터 기능 개요와 함께 다음 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

프로그래머의 길 멘토에게 묻다

프로그래머의 길 멘토에게 묻다

David Hoover, Adewale Oshineye, Kang Jung Bin
SRE를 위한 시스템 설계와 구축

SRE를 위한 시스템 설계와 구축

헤더 애드킨스, 벳시 바이어, 폴 블랭킨십, 피오트르 레반도프스키, 애나 오프레아, 애덤 스터블필드

Publisher Resources

ISBN: 9791169210966