[๋„์ „ ๊ธฐ์ˆ !] Web Layer

2021. 8. 23. 08:00ใ†Back-End ์ž‘์—…์‹ค/Spring Framework

728x90
๋ฐ˜์‘ํ˜•

์•ˆ๋…•ํ•˜์„ธ์š”? ์ฃผ๋‹ˆํ•˜๋ž‘ ์ž…๋‹ˆ๋‹ค.

๋ณธ ๋‚ด์šฉ์€ ์ฃผ๋‹ˆํ•˜๋ž‘์ด Web ๊ฐœ๋ฐœ ํ”„๋กœ์ ํŠธ๋ฅผ ํ•˜๋ฉด์„œ ๋„์ „ํ–ˆ๋˜ ๊ธฐ์ˆ ๋“ค์— ๋Œ€ํ•œ ๋‚ด์šฉ์„ ์ •๋ฆฌํ•˜๋Š” ๊ณณ ์ž…๋‹ˆ๋‹ค!

๋ฐ”๋กœ ์ฃผ๋‹ˆํ•˜๋ž‘์ด ์ •๋ฆฌํ•ด์„œ ์ž‘์„ฑํ•œ ๊ฒƒ์ด์—์š”.

์ฃผ๋‹ˆํ•˜๋ž‘์€ Back End ๊ฐœ๋ฐœ์„ ๋งก์•˜์—ˆ๋‹ต๋‹ˆ๋‹ค!




 

 

๐Ÿ™‹ Web Layer๋ฅผ ๊ตฌ์„ฑํ•˜๋ฉด์„œ ๋Š๋‚€์ 


๊ตญ๋น„์ง€์› ๊ต์œก์„ ๋ฐ›์œผ๋ฉด์„œ ์ฒซ๋ฒˆ์งธ ๊ต์œก์ด JAVA Servlet์„ ์ด์šฉํ•œ MVC๋ฅผ ์ด์šฉํ•ด์„œ JSP์™€ ํ•จ๊ป˜ Web Programing์„ ํ•˜๋Š” ๊ฒƒ์ด์˜€์Šต๋‹ˆ๋‹ค. ์ด ๋•Œ, VO, Controller, DAO, VIEW์— ๋Œ€ํ•ด ์ดํ•ด๋ฅผ ํ•˜์˜€๊ณ , ์ด๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ Project๋ฅผ ํ•˜์˜€์Šต๋‹ˆ๋‹ค.

๊ทธ๋Ÿฐ๋ฐ, Spring Boot๋ฅผ ์ด์šฉํ•˜๋ฉฐ, Web Layer์˜ ๊ฐœ๋…์„ ์ดํ•ดํ•˜๋ ค๊ณ  ํ•˜๋‹ˆ ์ž๊พธ VO, Controller, DAO, VIEW๋ผ๋Š” ๊ตฌ๋ถ„์œผ๋กœ Layer๋ฅผ ์ดํ•ดํ•˜๋ ค๊ณ  ํ•˜์—ฌ ์ดํ•ด๊ฐ€ ๋˜์ง€ ์•Š๊ณ , ์–ด๋ ต๊ฒŒ ๋Š๊ปด์กŒ์Šต๋‹ˆ๋‹ค.

๊ทธ๋Ÿฌ๋‹ค ๋ณด๋‹ˆ ๋น„์ฆˆ๋‹ˆ์Šค ๋กœ์ง์ด๋ผ๋Š” ๋‹จ์–ด๋„ ์ดํ•ด๊ฐ€ ๋˜์ง€ ์•Š์•˜๊ณ , ์ด ๊ธฐ๋ณธ์ด ์ดํ•ด๊ฐ€ ๋˜์ง€ ์•Š๋‹ค๋ณด๋‹ˆ ์ฝ”๋”ฉ์„ ํ•˜๋Š” ๊ฒƒ์ด ์–ด๋ ต๊ฒŒ ๋‹ค๊ฐ€์™”์Šต๋‹ˆ๋‹ค.

๊ฐ™์ด ํ”„๋กœ์ ํŠธ๋ฅผ ํ•˜๋ฉฐ, BackEnd ํŒ€์žฅ์ด ์ด๊ฒƒ์— ๋Œ€ํ•œ ์ข‹์€ ์ž๋ฃŒ๋ฅผ ๋งŽ์ด ์•Œ๋ ค์ฃผ์—ˆ๊ณ , Googling์„ ํ†ตํ•ด ๊ณต๋ถ€๋ฅผ ํ•œ ๊ฒฐ๊ณผ ์กฐ๊ธˆ์”ฉ ์ดํ•ด๊ฐ€ ๋˜์—ˆ๊ณ , ์ด๋ ‡๊ฒŒ ๋‚˜๋ˆ„์–ด์„œ ๊ตฌ์„ฑ์„ ํ•ด์•ผ SoC (Separation of Concerns)์˜ ๊ด€์‹ฌ์‚ฌ ๋ถ„๋ฆฌ ์›์น™๊ณผ KISS(Keep It Simple Stupid)๋ผ๋Š” ๊ฐ„๋‹จํ•˜๊ณ  ์•Œ๊ธฐ ์‰ฝ๊ฒŒ ๋งŒ๋“ค์ž๋ผ๋Š” ์›์น™์„ ์ง€ํ‚ฌ ์ˆ˜ ์žˆ๋‹ค๋Š” ๊ฒƒ์„ ์•Œ๊ฒŒ ๋˜์—ˆ๊ณ , ์•„ํ‚คํ…์ฒ˜ ๋””์ž์ธ์„ ์„ค๊ณ„ํ•˜๋Š”๋ฐ, ์ง€์ผœ์•ผํ•  ๊ธฐ๋ณธ ์›์น™์ด๋ผ๋Š” ๊ฒƒ์„ ์•Œ๊ฒŒ ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.

 

 

๐ŸŒ Web Layer


  • Controller์™€ View Templat ์˜์—ญ
  • Client Request / Respone์— ๊ด€ํ•œ ์ „๋ฐ˜์ ์ธ ์˜์—ญ
    • @Filter, Intercepter, @ControllerAdvice ๋“ฑ

์ €ํฌ๊ฐ€ ์ด๋ฒˆ Project์—์„œ ์‚ฌ์šฉํ–ˆ๋˜ Web Layer๋Š” ํฌ๊ฒŒ Controller์™€ Reate๋ฅผ ์ด์šฉํ•œ View Templat ๊ทธ๋ฆฌ๊ณ  Interceptor๊ฐ€ ์žˆ์œผ๋ฉฐ, Controller๋Š” RESTFulํ•˜๊ฒŒ ๊ตฌํ˜„ํ•˜๊ธฐ ์œ„ํ•˜์—ฌ REST Controller๋ฅผ ๊ตฌํ˜„ํ•˜์˜€์Šต๋‹ˆ๋‹ค.

์ด๋ฅผ ์œ„ํ•ด @RestController๋ฅผ ์‚ฌ์šฉํ•˜์˜€๊ณ , ์ด๊ฒƒ์€ Spring MVC Controller์— @ResponseBody๊ฐ€ ์ถ”๊ฐ€๋œ ๊ฒƒ์œผ๋กœ REST Controller๋Š” Json ํ˜•ํƒœ๋กœ Entity Data๋ฅผ ๋ฐ˜ํ™˜ ํ•ด์ฃผ๋Š” ์—ญํ• ์„ ํ•ฉ๋‹ˆ๋‹ค.

 

<์ถœ์ฒ˜ :  https://mangkyu.tistory.com/49 >

 

  • Client๋Š” URI ํ˜•์‹์œผ๋กœ Web Service์— ์š”์ฒญ
  • Mapping ๋˜๋Š” Handler์™€ Type์„ ์ฐพ๋Š” Dispatcher Servlet์ด Request๋ฅผ Interceptor
  • REST Controller๋Š” ํ•ด๋‹น Request๋ฅผ ์ฒ˜๋ฆฌํ•˜๊ณ , ๊ฒฐ๊ณผ๊ฐ’ Data ๋ฐ˜ํ™˜
packageudodog.goGetterServer.controller.api.bookreport;

importio.swagger.annotations.*;
importlombok.RequiredArgsConstructor;
importorg.springframework.data.domain.Page;
importorg.springframework.data.domain.Pageable;
importorg.springframework.data.domain.Sort;
importorg.springframework.data.web.PageableDefault;
importorg.springframework.hateoas.EntityModel;
importorg.springframework.http.HttpStatus;
importorg.springframework.http.ResponseEntity;
importorg.springframework.web.bind.annotation.GetMapping;
importorg.springframework.web.bind.annotation.RestController;
importudodog.goGetterServer.model.converter.bookreport.BookReportConverter;
importudodog.goGetterServer.model.dto.DefaultRes;
importudodog.goGetterServer.model.dto.response.bookreport.BookreportResponseDto;
importudodog.goGetterServer.service.bookreport.BookreportService;

@Api(tags = {"๋…์„œ ๊ธฐ๋ก ๊ด€๋ จ API"})
@RestController
@RequiredArgsConstructor
public classBookReportController {

private finalBookReportConverter bookReportConverter;
private finalBookreportService bookreportService;

    @ApiOperation( value = "๋…์„œ ๊ธฐ๋ก ์ „์ฒด ๋ชฉ๋ก ์กฐํšŒ API", notes = "๋…์„œ ๊ธฐ๋ก์˜ ์ „์ฒด ๋ชฉ๋ก ์กฐํšŒ API" )
    @ApiResponses( value = {
            @ApiResponse( code=200, message = "1. ์กฐํšŒ์„ฑ๊ณต \t\n 2. ๋ฐ์ดํ„ฐ์—†์Œ \t\n 3. ํ† ํฐ์—๋Ÿฌ" )
    })

//์ „์ฒด ์กฐํšŒ ๊ด€๋ จ Method
@GetMapping("/api/book-reports")
publicResponseEntity<EntityModel<DefaultRes<Page<BookreportResponseDto>>>> totalBookReportFindAll(
            @PageableDefault( sort = "id", direction = Sort.Direction.DESC, size = 10 )Pageablepageable ) {// Index Value๋ฅผ ์ด์šฉ ์ตœ์‹  ๋‚ ์งœ์ˆœ์„ ๊ธฐ์ค€์œผ๋กœ ๋‚ด๋ฆผ์ฐจ์ˆœ์œผ๋กœ ํŽ˜์ด์ง€๋‹น 10๊ฐœ์”ฉ ์ถœ๋ ฅ

return newResponseEntity<>(bookReportConverter.toModel( bookreportService.searchBookReportList(pageable)), HttpStatus.OK);
    }// totalBookReportFindAll()๋

}// Class๋

 

 

๐Ÿ™‡‍โ™‚๏ธ Service Layer


Client Request์— ๋”ฐ๋ฅธ Data ์ฒ˜๋ฆฌ๋ฅผ ํ•˜๋Š” ๊ณ„์ธต์œผ๋กœ ๋น„์ฆˆ๋‹ˆ์Šค, ํŠธ๋žœ์žญ์…˜ ์ฒ˜๋ฆฌ๋ฅผ ๋‹ด๋‹นํ•˜๋Š” ์˜์—ญ์œผ๋กœ, ๊ฐœ๋ฐœ ๋Œ€์ƒ์„ ๋ชจ๋“  ์‚ฌ๋žŒ์ด ๋™์ผํ•œ ๊ด€์ ์—์„œ ์ดํ•ดํ•  ์ˆ˜ ์žˆ๊ณ , ๊ณต์œ ํ•  ์ˆ˜ ์žˆ๋„๋ก ๋‹จ์ˆœํ™”.

 

๐Ÿ“Œ BookReportService.Class

@Service
@RequiredArgsConstructor
public class BookreportService {

private finalUserRepositoryuserRepository;
private finalBookReportRepositorybookReportRepository;
private finalBookReportQueryRepository bookReportQueryRepository;

//์ „์ฒด ์กฐํšŒ
publicDefaultRes<Page<BookreportResponseDto>> searchBookReportList(Pageablepageable) {//ํŽ˜์ด์ง• ์ฒ˜๋ฆฌ

Page<BookreportResponseDto> bookReportPage = bookReportQueryRepository.findAllWithFetchJoin(pageable);

if(bookReportPage.getTotalElements() == 0) {// bookreport์˜ ๋‚ด์šฉ์ด ์—†๋‹ค๋ฉด?
returnDefaultRes.response(HttpStatus.OK.value(), "๋ฐ์ดํ„ฐ์—†์Œ");

        }else{// bookreport์˜ ๋‚ด์šฉ์ด ์žˆ๋‹ค๋ฉด?
returnDefaultRes.response(HttpStatus.OK.value(), "์กฐํšŒ์„ฑ๊ณต", bookReportPage);
        }// if-else๋

}// searchBookReportList()๋

 

๐Ÿงท Domain Model


Back Ground์—์„œ ๋™์ž‘ํ•˜๋Š” ์ฃผ์š” Logic ์ฒ˜๋ฆฌํ•˜๋ฉฐ, Data๋ฅผ ๋‹ด๋‹น.

๋ณดํ†ต Data Base์™€ ์ง์ ‘์ ์ธ ์—ฐ๊ด€์„ ๋งบ์œผ๋ฉฐ ๋™์ž‘.

 

๐Ÿ’จ Entity


Data Base Table๊ณผ 1:1๋กœ Maping๋˜๋Š” Class.

์™ธ๋ถ€์—์„œ ๋ฌด๋ถ„๋ณ„ํ•œ getter์™€ setter๋กœ ์ธํ•ด Data์˜ ์˜ค์—ผ์ด ๋ฐœ์ƒํ•˜๋ฉด ์•ˆ๋˜๊ธฐ์— ๋‚ด๋ถ€ Method๋กœ Data ์กฐ์ž‘ ํ•„์š”.

์ €ํฌ๋Š” ์œ„์—์„œ ์ž‘์„ฑํ•œ Data ์˜ค์—ผ์„ ๋ฐฉ์ง€ํ•˜๊ธฐ ์œ„ํ•˜์—ฌ Setter๋ฅผ ์ œ์™ธํ•˜๊ณ , @Getter์™€ @Bulder๋ฅผ ํ†ตํ•ด Data ์ฃผ์ž…์„ ์‚ฌ์šฉํ•˜์˜€์Šต๋‹ˆ๋‹ค.

Effective Java ๊ทœ์น™ 2 - ์กฐ์Šˆ์•„ ๋ธ”๋กœํฌ

์ƒ์„ฑ์ž์— ์ธ์ž๊ฐ€ ๋งŽ์„ ๋•Œ๋Š” ๋นŒ๋” ํŒจํ„ด์„ ๊ณ ๋ คํ•˜๋ผ.

๋นŒ๋” ํŒจํ„ด(Builder Pattern)์ด๋ž€ ๋ณตํ•ฉ ๊ฐ์ฒด์˜ ์ƒ์„ฑ ๊ณผ์ •๊ณผ ํ‘œํ˜„ ๋ฐฉ๋ฒ•์„ ๋ถ„๋ฆฌํ•˜์—ฌ ๋™์ผํ•œ ์ƒ์„ฑ ์ ˆ์ฐจ์—์„œ ์„œ๋กœ ๋‹ค๋ฅธ ํ‘œํ˜„ ๊ฒฐ๊ณผ๋ฅผ ๋งŒ๋“ค ์ˆ˜ ์žˆ๊ฒŒ ํ•ด ์ฃผ๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค.

Builder Pattern์„ ์‚ฌ์šฉํ•˜๋ฉด ๊ฐ์ฒด๋“ค๋งˆ๋‹ค ๋“ค์–ด๊ฐ€์•ผํ•  ์ธ์ž๊ฐ€ ๊ฐ๊ฐ ๋‹ค๋ฅผ ๋•Œ ์œ ์—ฐํ•˜๊ฒŒ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์œผ๋ฉฐ, ๋ถ€๋ถ„๋ณ„ํ•œ Setter ์ƒ์„ฑ์„ ๋ฐฉ์ง€ํ•˜๊ณ , ๋ถˆํŽธ ๊ฐ์ฒด๋กœ ๋งŒ๋“ค ์ˆ˜๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค. ๋˜ํ•œ, ํ•„์ˆ˜ Argument๋ฅผ ์ง€์ •ํ•  ์ˆ˜ ์žˆ๊ฒŒ ๋ฉ๋‹ˆ๋‹ค. (๋ณดํ†ต์˜ ๊ฒฝ์šฐ PK ์—ญํ• ์„ ํ•  ID Value) ์ด๋ ‡๊ฒŒ ํ•˜์—ฌ Service์™€ ๊ฐ™์€ ๊ณณ์—์„œ BookReport.builder(). { ์—ฌ๋Ÿฌ๊ฐ€์ง€ Field์˜ ์ดˆ๊ธฐ๊ฐ’ ์„ ์–ธ }.build() ํ˜•ํƒœ๋กœ ๊ฐ์ฒด๋ฅผ ๋งŒ๋“ค ์ˆ˜ ์žˆ๊ฒŒ ํ•˜์˜€์Šต๋‹ˆ๋‹ค.

์œ„์˜ ๋‚ด์šฉ์œผ๋กœ ์ €ํฌ๋Š” ์•„๋ž˜์™€ ๊ฐ™์ด ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•˜์—ฌ Entity๋ฅผ ์‚ฌ์šฉํ•˜์˜€์Šต๋‹ˆ๋‹ค.

 

๐Ÿ“Œ BookReport.java

@Getter
@NoArgsConstructor
@Entity
@EntityListeners(AuditingEntityListener.class)
public class BookReport {

@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
privateLong bookReportId;

@ManyToOne(targetEntity = User.class, fetch = FetchType.LAZY)
@JoinColumn(name = "user_id")
privateUser user;

privateString title;

privateString bookName;

privateString content;

@CreatedDate privateLocalDateTime createdAt;

@Builder
publicBookReport(User user, String title, String bookName, String content) {
this.user = user;
this.title = title;
this.bookName = bookName;
this.content = content;

}//์ƒ์„ฑ์ž ๋

@ManyToOne์€ ํ•ด๋‹น Entity์™€ ๋‹ค๋ฅธ Entity ๊ฐ„์— ๊ด€๊ณ„๋ฅผ ์ง“๊ธฐ ์œ„ํ•˜์—ฌ ์‚ฌ์šฉํ•˜์˜€์Šต๋‹ˆ๋‹ค.

์ด๊ฒƒ์€ Writer ์ž…์žฅ์—์„œ BookReport๊ฐ€ ์—ฌ๋Ÿฌ ๊ฐœ๊ฐ€ ๋  ์ˆ˜ ์žˆ๊ธฐ ๋•Œ๋ฌธ์— Writer : BookReport = 1 : N ๊ด€๊ณ„๊ฐ€ ๋˜๊ธฐ ๋•Œ๋ฌธ์— ์‚ฌ์šฉ ํ•˜์˜€์Šต๋‹ˆ๋‹ค.

@Id, @GeneratedValue๋Š” ํ•ด๋‹น Entity์˜ ์ฃผ์š” ํ‚ค (Primary Key, PK)๊ฐ€ ๋  ๊ฐ’์„ ์ง€์ •ํ•˜๊ธฐ ์œ„ํ•˜์—ฌ @Id๋ฅผ ์‚ฌ์šฉํ•˜์˜€๊ณ , @GenneratedValue๋Š” ์ด PK๊ฐ€ ์ž๋™์œผ๋กœ 1์”ฉ ์ฆ๊ฐ€ํ•˜๋Š” ํ˜•ํƒœ๋กœ ์ƒ์„ฑ๋ ์ง€ ๋“ฑ์„ ๊ฒฐ์ •ํ•˜๊ธฐ ์œ„ํ•ด ์‚ฌ์šฉํ•˜์˜€์Šต๋‹ˆ๋‹ค.

 

๐Ÿ’จ Data Transfer Object


Data Transfer Object์˜ ์•ฝ์ž, Data ์ „์†ก ๊ณ„์ธต ๋‹ด๋‹น.

Data๋ฅผ Layer(Controller, Service ๋“ฑ) ๊ฐ„ ์ด๋™ ์‹œํ‚ฌ ๋•Œ ์‚ฌ์šฉ.

๊ฐ€๋Šฅํ•œ Data ์ „๋‹ฌ ์ด์™ธ ๊ธฐ๋Šฅ์€ ์ด ๊ณณ์— ๋„ฃ์ง€ ์•Š์Œ.

๊ณ„์ธต ๊ฐ„ Data ๊ตํ™˜์„ ์œ„ํ•œ Object.

 

๐Ÿ“Œ BookreportResponseDto.java

@Getter
public class BookreportResponseDto {

privateLong bookReportId;             //๋…์„œ ๊ธฐ๋ก Index๋ฒˆํ˜ธ
privateString userNickname;           // User Nickname
privateString bookName;               //์ฑ… ์ œ๋ชฉ
privateString title;                  //๋…์„œ ๊ธฐ๋ก ๊ธ€ ์ œ๋ชฉ
privateLocalDate createAt;            //์ž‘์„ฑ์ผ

publicBookreportResponseDto ( Long bookReportId, String userNickname, String bookName, String title, LocalDate createAt ) {

this.bookReportId = bookReportId;
this.userNickname = userNickname;
this.bookName = bookName;
this.title = title;
this.createAt = createAt;

} //์ƒ์„ฑ์ž ๋

์œ„์˜ ์ฝ”๋“œ๋Š” Client์—๊ฒŒ ์ „๋‹ฌํ•  Value์— ๋Œ€ํ•ด Data๋ฅผ ์ „์†กํ•˜๊ธฐ ์œ„ํ•ด ๋งŒ๋“  Response DTO ์ž…๋‹ˆ๋‹ค.

DATA ์ฃผ์ž…์— ๋Œ€ํ•œ ๋‚ด์šฉ ์™ธ์—๋Š” DTO์— ๋‹ค๋ฅธ ๋‚ด์šฉ์„ ๋„ฃ์œผ๋ฉด ์•ˆ๋œ๋‹ค๋Š” ๊ฒƒ์„ ๊ธฐ๋ฐ˜์œผ๋กœ ํ•˜์—ฌ Field ๋ณ€์ˆ˜์™€ ์ƒ์„ฑ์ž, @Getter ์™ธ์—๋Š” ๋‚ด์šฉ์„ ์ถ”๊ฐ€ํ•˜์ง€ ์•Š์•˜์Šต๋‹ˆ๋‹ค.

 

๐Ÿ’จ Repository


DataBase์— ์ง์ ‘ ์ ‘๊ทผํ•˜๋Š” ๊ณ„์ธต์œผ๋กœ, DAO ์˜์—ญ์— ํ•ด๋‹น.

 

๐Ÿ“Œ BookReportRepository.java

public interface BookReportRepository extends JpaRepository < BookReport, Long > {

}

์œ„์˜ BookReportRepository๋Š” interface์ด๋ฉฐ, JpaRepository๋ฅผ ์ƒ์†ํ•˜๊ฒŒ ๊ตฌ์„ฑํ•˜์˜€์Šต๋‹ˆ๋‹ค.

ID Value ๊ธฐ๋ฐ˜์œผ๋กœ ๊ธฐ๋ณธ์ ์ธ interface๋“ค์ด ์„ ์–ธ ๋˜์–ด ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ๊ทธ ์™ธ ๊ธฐ๋Šฅ์€ ์œ„์™€ ๊ฐ™์ด ๊ทœ์น™์— ๋งž๊ฒŒ ๊ตฌ์„ฑ์„ ํ•˜์˜€์Šต๋‹ˆ๋‹ค.

 

๐Ÿ“Œ BookReportQueryRepository.java (For querydsl)

@RequiredArgsConstructor
@Repository
public class BookReportQueryRepository {

private finalJPAQueryFactory jpaQueryFactory;
private finalEntityManagerentityManager;

//์ „์ฒด ์กฐํšŒ
publicPage<BookreportResponseDto> findAllWithFetchJoin(Pageablepageable) { //ํŽ˜์ด์ง• ์ฒ˜๋ฆฌ

List<BookreportResponseDto> reportList = jpaQueryFactory.select(Projections.fields(
		BookreportResponseDto.class,
		bookReport.bookReportId,
		bookReport.user,
		bookReport.title,
		bookReport.createdAt))
		           .from(bookReport)
		           .innerJoin(bookReport.user,user)
		           .fetch();

		intstart = (int)pageable.getOffset();
		intend = Math.min((start + pageable.getPageSize()), reportList.size() );

return newPageImpl<>(reportList.subList(start, end), pageable, reportList.size());
  } // reportList๋

} // Class๋

 

์ €ํฌ๊ฐ€ Querydsl์„ ์‚ฌ์šฉํ•œ ์ด์œ ๋Š” Jap๋ฅผ ํ†ตํ•ด ๊ธฐ๋ณธ์ ์œผ๋กœ ์ œ๊ณตํ•ด ์ฃผ๋Š” @Query๋กœ๋Š” ๋‹ค์–‘ํ•œ ์กฐํšŒ ๊ธฐ๋Šฅ์„ ์‚ฌ์šฉํ•˜๋Š”๋ฐ, ํ•œ๊ณ„๊ฐ€ ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ์‚ฌ์šฉํ•˜์˜€์Šต๋‹ˆ๋‹ค.

๊ทธ๋ž˜์„œ ์œ„์™€ ๊ฐ™์€ ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•˜๊ธฐ ์œ„ํ•ด Static Type์„ ์ง€์›ํ•˜๋Š” ์กฐํšŒ ํ”„๋ ˆ์ž„์›Œํฌ๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•ด Querydsl์„ ์„ ํƒํ•˜์—ฌ ์‚ฌ์šฉํ•˜์˜€์Šต๋‹ˆ๋‹ค.

 

 


 

์ฃผ๋‹ˆํ•˜๋ž‘์˜ ๊ธ€์ด ๋งˆ์Œ์— ๋“œ์…จ๋‚˜์š”? ๊ตฌ๋…๊ณผ ๊ณต๊ฐ! ๊ทธ๋ฆฌ๊ณ , ๋Œ“๊ธ€์€ ์ฃผ๋‹ˆํ•˜๋ž‘์—๊ฒŒ ๋งŽ์€ ํž˜์ด ๋ฉ๋‹ˆ๋‹ค

728x90
๋ฐ˜์‘ํ˜•

'Back-End ์ž‘์—…์‹ค > Spring Framework' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

[๋„์ „ ๊ธฐ์ˆ !] JPA์™€ Querydsl  (0) 2021.08.25
[๋„์ „ ๊ธฐ์ˆ !] ํ…Œ์ŠคํŠธ ์ฝ”๋“œ  (0) 2021.08.24
[Spring Boot] AOP  (0) 2021.08.20
[Spring Boot] Spring Data JPA  (0) 2021.08.19
[Spring Boot] JPA  (0) 2021.08.18