๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
  • ์žฅ์›์ต ๊ธฐ์ˆ ๋ธ”๋กœ๊ทธ
๐Ÿ“š ์‹œ๋ฆฌ์ฆˆ/- ๋ฐฐ์›Œ๋ณด์ž Spring Data JPA

[๋ฐฐ์›Œ๋ณด์ž Spring Data JPA] JPA ์—์„œ Pageable ์„ ์ด์šฉํ•œ ํŽ˜์ด์ง•๊ณผ ์ •๋ ฌ

by Wonit 2021. 4. 11.

ํ•ด๋‹น ๊ธ€์€ ๋ฐฐ์›Œ๋ณด์ž Spring Data JPA ์‹œ๋ฆฌ์ฆˆ ์ž…๋‹ˆ๋‹ค.
ํ•ด๋‹น ์‹œ๋ฆฌ์ฆˆ์˜ ๋‚ด์šฉ์ด ์ด์–ด์ง€๋Š” ํ˜•ํƒœ์ด๋ฏ€๋กœ ๊ธ€์˜ ๋‚ด์šฉ ์ค‘์— ์ƒ๋žต๋˜๋Š” ๋ง๋“ค์ด ์žˆ์„ ์ˆ˜ ์žˆ์œผ๋‹ˆ, ์ž์„ธํ•œ ์‚ฌํ•ญ์€ ์•„๋ž˜ ๋งํฌ๋ฅผ ์ฐธ๊ณ ํ•ด์ฃผ์„ธ์š”!


๊ฒŒ์‹œํŒ์ด๋‚˜ ๋Œ“๊ธ€, ๋ธ”๋กœ๊ทธ๋ฅผ ๊ฐœ๋ฐœํ•  ๋•Œ ํŽ˜์ด์ง•์€ ์•„์ฃผ ์ค‘์š”ํ•œ ์—ญํ• ์„ ํ•œ๋‹ค.

 

ํŽ˜์ด์ง•์€ ๋งŽ์€ ์ •๋ณด, ์ด๋ฅผํ…Œ๋ฉด ๊ฒŒ์‹œํŒ์— ์กด์žฌํ•˜๋Š” ์ˆ˜๋ฐฑ ์ˆ˜์ฒœ๊ฐœ์˜ ๊ฒŒ์‹œ๊ธ€๊ณผ ๊ฐ™์€ ์ •๋ณด๋“ค์„ ํŽ˜์ด์ง€๋กœ ๋‚˜๋ˆ  ํšจ๊ณผ์ ์œผ๋กœ ์ •๋ณด๋ฅผ ์ œ๊ณตํ•˜๊ฒŒ ํ•˜๋Š” ์—ญํ• ์„ ํ•œ๋‹ค.

 

ํŽ˜์ด์ง•

 

์ด๋Ÿฌํ•œ ํŽ˜์ด์ง•์„ ๊ฐœ๋ฐœํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” page ๊ด€๋ จ ์ฟผ๋ฆฌ๋ฅผ ํŒŒ๋ผ๋ฏธํ„ฐ๋กœ ๋ฐ›์•„์„œ ์ง์ ‘ ์ฒ˜๋ฆฌํ•˜๋Š” ๋ฐฉ๋ฒ•์ด ์žˆ์—ˆ์ง€๋งŒ JPA ์—์„œ ๋˜ Spring Data ํ”„๋กœ์ ํŠธ์—์„œ๋Š” ํšจ๊ณผ์ ์œผ๋กœ ํŽ˜์ด์ง•์„ ์ฒ˜๋ฆฌํ•  ์ˆ˜ ์žˆ๊ฒŒ ๋ฐฉ๋ฒ•์„ ์ œ๊ณตํ•œ๋‹ค.

 

Spring Data JPA ์—์„œ์˜ ํŽ˜์ด์ง•๊ณผ ์ •๋ ฌ

Spring Data JPA ์—์„œ๋Š” ์•ž์„œ ๋ง ํ–ˆ๋“ฏ ํŽ˜์ด์ง•๊ณผ ์ •๋ ฌ์— ์•„์ฃผ ๊ฐ•๋ ฅํ•œ ๋ฐฉ๋ฒ•์„ ์ œ๊ณตํ•œ๋‹ค.

 

์ง€๋‚œ ์‹œ๊ฐ„์— ๋ดค๋˜ JpaRepository ์ธํ„ฐํŽ˜์ด์Šค์˜ ์ƒ์† ๋‹ค์ด์–ด๊ทธ๋žจ์„ ์‚ดํŽด๋ณด์ž.

 

JpaRepository ์˜ ๋ถ€๋ชจ ์ธํ„ฐํŽ˜์ด์Šค์ธ PagingAndSortingRepository ์—์„œ ํŽ˜์ด์ง•๊ณผ ์†ŒํŒ…์ด๋ผ๋Š” ๊ธฐ๋Šฅ์„ ์ œ๊ณตํ•œ๋‹ค.

 

findAll() ๋ฉ”์„œ๋“œ์˜ ๋ฐ˜ํ™˜ ํƒ€์ž…๊ณผ ํŒŒ๋ผ๋ฏธํ„ฐ๋ฅผ ๋ณด๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๊ฒƒ๋“ค์ด ์กด์žฌํ•œ๋‹ค.

 

  • org.springframework.data.domain.Pageable
    • ํŽ˜์ด์ง•์„ ์ œ๊ณตํ•˜๋Š” ์ค‘์š”ํ•œ ์ธํ„ฐํŽ˜์ด์Šค์ด๋‹ค.
  • org.springframework.data.domain.Page
    • ํŽ˜์ด์ง•์˜ findAll() ์˜ ๊ธฐ๋ณธ์ ์ธ ๋ฐ˜ํ™˜ ๋ฉ”์„œ๋“œ๋กœ ์—ฌ๋Ÿฌ ๋ฐ˜ํ™˜ ํƒ€์ž… ์ค‘ ํ•˜๋‚˜์ด๋‹ค.

๊ฒฐ๊ตญ ์šฐ๋ฆฌ๋Š” JpaRepository<> ๋ฅผ ์‚ฌ์šฉํ•  ๋•Œ, findAll() ๋ฉ”์„œ๋“œ๋ฅผ Pageable ์ธํ„ฐํŽ˜์ด์Šค๋กœ ํŒŒ๋ผ๋ฏธํ„ฐ๋ฅผ ๋„˜๊ธฐ๋ฉด ํŽ˜์ด์ง•์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๊ฒŒ๋œ๋‹ค.

 

ํ•œ ๋ฒˆ ์‚ฌ์šฉํ•ด๋ณด์ž.

 

์ด๋ฒˆ์—๋Š” controller ๋ฅผ ๋งŒ๋“ค์–ด์„œ ์‚ฌ์šฉํ•ด๋ณด์ž.

 

@RestController
public class UserController {

    private final UserRepository userRepository;

    public UserController(UserRepository userRepository) {
        this.userRepository = userRepository;
    }

    @GetMapping("/users")
    public Page<User> getAllUsers() {
        PageRequest pageRequest = PageRequest.of(0, 5);
        return userRepository.findAll(pageRequest);
    }

    @PostConstruct
    public void initializing() {
        for (int i = 0; i < 100; i++) {
            User user = User.builder()
                    .username("User " + i)
                    .address("Korea")
                    .age(i)
                    .build();
            userRepository.save(user);
        }
    }
}

getAllUsers() ๋ฉ”์„œ๋“œ์— ๋ณด๋ฉด PageRequest ๊ฐ์ฒด๊ฐ€ ์กด์žฌํ•œ๋‹ค.

 

PageRequest ๊ฐ์ฒด๋Š” Pageable ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ์ƒ์†๋ฐ›๋Š”๋‹ค.

 

์‰ฝ๊ฒŒ Paging ์„ ์œ„ํ•œ ์ •๋ณด๋ฅผ ๋„˜๊ธธ ์ˆ˜ ์žˆ๋Š”๋ฐ, ์ด ์ •๋ณด์—๋Š” ์ •๋ ฌ ์ •๋ณด, ํŽ˜์ด์ง€ offset, page์™€ ๊ฐ™์€ ์ •๋ณด๊ฐ€ ๋‹ด๊ฒจ์žˆ๋‹ค.

 

์›๋ž˜๋ผ๋ฉด ๊ธฐ๋ณธ์ ์œผ๋กœ ๋ฐ์ดํ„ฐ๊ฐ€ DB์— ์ €์žฅ๋˜์–ด ์žˆ์–ด์•ผํ•œ๋‹ค.
ํ•˜์ง€๋งŒ ์šฐ๋ฆฌ๋Š” hibernate ์ „๋žต์„ create ๋กœ ์žก์•˜๊ธฐ ๋•Œ๋ฌธ์— DB์— ์ €์žฅํ•˜๋Š” ๊ฒƒ์ด ํž˜๋“ค๋‹ค.
๋ฌผ๋ก  hibernate.ddl-auto ์ „๋žต์„ update ๋กœ ์žก๋Š”๋‹ค๋ฉด DB์— ์ €์žฅํ•  ์ˆ˜ ์žˆ์ง€๋งŒ ํŽ˜์ด์ง•์„ ํ…Œ์ŠคํŠธํ•  100๊ฐœ์˜ ๋ฐ์ดํ„ฐ๋ฅผ ๋‹ค ๋„ฃ๋Š” ๊ฒƒ ๋ณด๋‹ค Spring ์—์„œ ์ œ๊ณตํ•˜๋Š” ์ดˆ๊ธฐํ™” ๋ฉ”์„œ๋“œ๋ฅผ ์ด์šฉํ•ด์„œ ์ดˆ๊ธฐํ™”๋ฅผ ํ•  ๊ฒƒ์ด๋‹ค.

initializing() ์„ ์ด์šฉํ•ด์„œ 100๋ช…์˜ ๋ฐ์ดํ„ฐ๋ฅผ ์ถ”๊ฐ€ํ•ด์ฃผ๊ณ  api ํ˜ธ์ถœ์„ ํ•ด๋ณด์ž.

 

api ํ˜ธ์ถœ์„ ๋ธŒ๋ผ์šฐ์ €์—์„œ ์ง์ ‘ url ๋กœ ํ•ด๋„ ์ข‹๊ณ  curl ์„ ํ•ด๋„ ์ข‹์ง€๋งŒ ๋‚˜๋Š” Postman์„ ์ด์šฉํ•  ๊ฒƒ์ด๋‹ค.

๊ฒฐ๊ณผ๋ฅผ ๋ด๋ณด์ž.

"content":[
{
    "content": [
        {"id": 1, "username": "User 0", "address": "Korea", "age": 0},
        // ์ค‘๊ฐ„ ์ƒ๋žต
        {"id": 5, "username": "User 4", "address": "Korea", "age": 4}
    ],
    "pageable": {
        "sort": {
            "sorted": false, // ์ •๋ ฌ ์ƒํƒœ
            "unsorted": true,
            "empty": true
        },
        "pageSize": 5, // ํ•œ ํŽ˜์ด์ง€์—์„œ ๋‚˜ํƒ€๋‚ด๋Š” ์›์†Œ์˜ ์ˆ˜ (๊ฒŒ์‹œ๊ธ€ ์ˆ˜)
        "pageNumber": 0, // ํŽ˜์ด์ง€ ๋ฒˆํ˜ธ (0๋ฒˆ ๋ถ€ํ„ฐ ์‹œ์ž‘)
        "offset": 0, // ํ•ด๋‹น ํŽ˜์ด์ง€์— ์ฒซ ๋ฒˆ์งธ ์›์†Œ์˜ ์ˆ˜
        "paged": true,
        "unpaged": false
    },
    "totalPages": 20, // ํŽ˜์ด์ง€๋กœ ์ œ๊ณต๋˜๋Š” ์ด ํŽ˜์ด์ง€ ์ˆ˜
    "totalElements": 100, // ๋ชจ๋“  ํŽ˜์ด์ง€์— ์กด์žฌํ•˜๋Š” ์ด ์›์†Œ ์ˆ˜
    "last": false,
    "number": 0,
    "sort": {
        "sorted": false,
        "unsorted": true,
        "empty": true
    },
    "size": 5,
    "numberOfElements": 5,
    "first": true,
    "empty": false
}

์ด์™€ ๊ฐ™์ด Paging ์ด ์ ์šฉ๋œ ์‘๋‹ต์„ ๋ฐ›์„ ์ˆ˜ ์žˆ๋‹ค.

 

content ์•„๋ž˜์— ์žˆ๋Š” ๋ฐ์ดํ„ฐ๋“ค์ด paging ๊ณผ ๊ด€๋ จ๋œ ์ •๋ณด๋“ค์ด๋‹ค.

 

๋ฉ‹์ง€๋‹ค.

 

ํ•˜์ง€๋งŒ ๋” ๋ฉ‹์ง„ ๊ฒƒ์€ ์ฟผ๋ฆฌ ๋ฉ”์„œ๋“œ ๊ธฐ๋Šฅ์—์„œ๋„ ์ œ๊ณตํ•œ๋‹ค๋Š” ๊ฒƒ์ด๋‹ค.

์ฟผ๋ฆฌ ๋ฉ”์„œ๋“œ์—์„œ ํŽ˜์ด์ง• ์‚ฌ์šฉํ•˜๊ธฐ

public interface UserRepository extends JpaRepository<User, Long> {
    Page<User> findByAddress(String address, Pageable pageable);
}

์ด๋ ‡๊ฒŒ ์‚ฌ์šฉ์ž์˜ ์ฃผ์†Œ๋กœ ์กฐํšŒํ•˜๋Š” ์ฟผ๋ฆฌ ๋ฉ”์„œ๋“œ๋ฅผ ๋งŒ๋“ค๊ณ  ๋‘ ๋ฒˆ์งธ ํŒŒ๋ผ๋ฏธํ„ฐ๋กœ Pageable ์„ ๋„˜๊ฒจ์ฃผ๋ฉด ๋œ๋‹ค.

 

๊ทธ๋ฆฌ๊ณ  ์ปจํŠธ๋กค๋Ÿฌ์— ๊ฐ€์„œ ๋‹ค์‹œ PageRequest ๋ฅผ ๋งŒ๋“ค์–ด์ฃผ์ž.

 

์ด๋ฒˆ์—๋Š” ๋” ๋‚˜์•„๊ฐ€ ์ฟผ๋ฆฌ ํŒŒ๋ผ๋ฏธํ„ฐ๋กœ ๋„˜์–ด์˜จ ๊ฐ’์„ ํŽ˜์ด์ง€ ์ •๋ณด๋กœ ๋งŒ๋“ค์–ด ๋ณผ ๊ฒƒ์ด๋‹ค.

@RestController
public class UserController {

    private final UserRepository userRepository;

    public UserController(UserRepository userRepository) {
        this.userRepository = userRepository;
    }

    @GetMapping("/users")
    public Page<User> getAllUserWithPageByQueryMethod(@RequestParam("page") Integer page, @RequestParam("size") Integer size) {
        PageRequest pageRequest = PageRequest.of(page, size);
        return userRepository.findByAddress("Korea", pageRequest);
    }


    @PostConstruct
    public void initializing() {
        for (int i = 0; i < 100; i++) {
            User user = User.builder()
                    .username("User " + i)
                    .address("Korea")
                    .age(i)
                    .build();
            userRepository.save(user);
        }
    }
}

 

์ด๋ ‡๊ฒŒ ๋งŒ๋“ค๊ณ  http://localhost:8080/users/?page=3&size=4 ๋กœ ์š”์ฒญ์„ ๋ณด๋‚ด๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๊ฒฐ๊ณผ๊ฐ€ ์ถœ๋ ฅ๋œ๋‹ค.

 

{
  "content": [
    { "id": 13, "username": "User 12", "address": "Korea", "age": 12 },
    { "id": 14, "username": "User 13", "address": "Korea", "age": 13 },
    { "id": 15, "username": "User 14", "address": "Korea", "age": 14 },
    { "id": 16, "username": "User 15", "address": "Korea", "age": 15 }
  ],
  "pageable": {
    "sort": { "sorted": false, "unsorted": true, "empty": true },
    "pageNumber": 3,
    "pageSize": 4,
    "offset": 12,
    "paged": true,
    "unpaged": false
  },
  "totalPages": 25,
  "totalElements": 100,
  "last": false,
  "numberOfElements": 4,
  "number": 3,
  "sort": { "sorted": false, "unsorted": true, "empty": true },
  "size": 4,
  "first": false,
  "empty": false
}

๋ฐ˜ํ™˜ ํƒ€์ž…์— ๋”ฐ๋ฅธ ํŽ˜์ด์ง• ๊ฒฐ๊ณผ

Spring Data JPA ์—๋Š” ๋ฐ˜ํ™˜ ํƒ€์ž…์— ๋”ฐ๋ผ์„œ ๊ฐ๊ธฐ ๋‹ค๋ฅธ ๊ฒฐ๊ณผ๋ฅผ ์ œ๊ณตํ•œ๋‹ค.

 

  1. Page<T> ํƒ€์ž…
  2. Slice<T> ํƒ€์ž…
  3. List<T> ํƒ€์ž…

๊ฐ์ž ๋‹ค๋ฅธ ๊ฒฐ๊ณผ๋ฅผ ๋ฐ˜ํ™˜ํ•ด์ค€๋‹ค.

Page<T> ํƒ€์ž…

Page<T> ํƒ€์ž…์„ ๋ฐ˜ํ™˜ ํƒ€์ž…์œผ๋กœ ๋ฐ›๊ฒŒ ๋œ๋‹ค๋ฉด offset๊ณผ totalPage ๋ฅผ ์ด์šฉํ•˜์—ฌ ์„œ๋น„์Šค๋ฅผ ์ œ๊ณตํ•  ์ˆ˜ ์žˆ๊ฒŒ๋œ๋‹ค.

 

Page<T> ๋Š” ์ผ๋ฐ˜์ ์ธ ๊ฒŒ์‹œํŒ ํ˜•ํƒœ์˜ ํŽ˜์ด์ง•์—์„œ ์‚ฌ์šฉ๋œ๋‹ค.

 

์—ฌ๊ธฐ์„œ ์ค‘์š”ํ•œ ์ •๋ณด๋Š” ์ด ํŽ˜์ด์ง€ ์ˆ˜ ์ด๋‹ค.

 

๊ทธ ์ •๋ณด๋ฅผ ํฌํ•จํ•˜์—ฌ ๋ฐ˜ํ™˜ํ•œ๋‹ค.

 

Page<T> ํƒ€์ž…์€ count ์ฟผ๋ฆฌ๋ฅผ ํฌํ•จํ•˜๋Š” ํŽ˜์ด์ง•์œผ๋กœ ์นด์šดํŠธ ์ฟผ๋ฆฌ๊ฐ€ ์ž๋™์œผ๋กœ ์ƒ์„ฑ๋˜์–ด ํ•จ๊ป˜ ๋‚˜๊ฐ„๋‹ค.

Slice<T> ํƒ€์ž…

Slice<T> ํƒ€์ž…์„ ๋ฐ˜ํ™˜ ํƒ€์ž…์œผ๋กœ ๋ฐ›๊ฒŒ ๋œ๋‹ค๋ฉด ๋”๋ณด๊ธฐ ํ˜•ํƒœ์˜ ํŽ˜์ด์ง•์—์„œ ์‚ฌ์šฉ๋œ๋‹ค.

 

 

์‘๋‹ต์„ ์‚ดํŽด๋ณด์ž.

 

{
  "content": [
    { "id": 13, "username": "User 12", "address": "Korea", "age": 12 },
    { "id": 14, "username": "User 13", "address": "Korea", "age": 13 },
    { "id": 15, "username": "User 14", "address": "Korea", "age": 14 },
    { "id": 16, "username": "User 15", "address": "Korea", "age": 15 }
  ],
  "pageable": {
    "sort": { "sorted": false, "unsorted": true, "empty": true },
    "pageNumber": 3,
    "pageSize": 4,
    "offset": 12,
    "paged": true,
    "unpaged": false
  },
  "number": 3,
  "numberOfElements": 4,
  "first": false,
  "last": false,
  "size": 4,
  "sort": { "sorted": false, "unsorted": true, "empty": true },
  "empty": false
}

Page<T> ํƒ€์ž…์˜ ๋ฐ˜ํ™˜์— ์—†๋Š” ๊ฒƒ๋“ค์ด ์กด์žฌํ•œ๋‹ค.


number๊ณผ numberOfElements ๊ทธ๋ฆฌ๊ณ  Page<T> ์— ์กด์žฌํ•˜๋˜ totalPages, totalElements ๊ฐ€ ์—†์–ด์กŒ๋‹ค.

 

Slice<T> ํƒ€์ž…์€ ์ถ”๊ฐ€ count ์ฟผ๋ฆฌ ์—†์ด ๋‹ค์Œ ํŽ˜์ด์ง€ ํ™•์ธ ๊ฐ€๋Šฅํ•˜๋‹ค. ๋‚ด๋ถ€์ ์œผ๋กœ limit + 1 ์กฐํšŒ๋ฅผ ํ•ด์„œ totalCount ์ฟผ๋ฆฌ๊ฐ€ ๋‚˜๊ฐ€์ง€ ์•Š์•„์„œ ์„ฑ๋Šฅ์ƒ ์กฐ๊ธˆ ์ด์ ์„ ๋ณผ ์ˆ˜๋„ ์žˆ๋‹ค.

List<T> ํƒ€์ž…

@GetMapping("/users")
public List<User> getAllUsers(Pageable pageable) {
  return userRepository.findAll(pageable);
}

List ๋ฐ˜ํ™˜ ํƒ€์ž…์€ ๊ฐ€์žฅ ๊ธฐ๋ณธ์ ์ธ ๋ฐฉ๋ฒ•์œผ๋กœ count ์ฟผ๋ฆฌ ์—†์ด ๊ฒฐ๊ณผ๋งŒ ๋ฐ˜ํ™˜ํ•œ๋‹ค.

 

Spring Web MVC ์—์„œ ๋” ํŽธํ•˜๊ฒŒ ํŽ˜์ด์ง•ํ•˜๊ธฐ

Spring Data JPA์˜ ํŽ˜์ด์ง•๊ณผ ์ •๋ ฌ ๊ธฐ๋Šฅ๋ณด๋‹ค ํ›จ์”ฌ ๊ฐ„ํŽธํ•˜๊ฒŒ MVC ์—์„œ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•œ๋‹ค.

 

์ฆ‰, ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์‚ฌ์šฉ์ž๊ฐ€ ์ •์˜ํ•œ ํŒŒ๋ผ๋ฏธํ„ฐ์— ๋”ฐ๋ผ์„œ๋„ ํŽ˜์ด์ง•์ด ๊ฐ€๋Šฅํ•˜๋‹ค๋Š” ์†Œ๋ฆฌ์ด๋‹ค.

 

@GetMapping("/users")
public Page<User> getAllUsers(Pageable pageable) {
    return userRepository.findAll(pageable);
}

์ปจํŠธ๋กค๋Ÿฌ์—์„œ @GetMapping ์— ํŒŒ๋ฆฌ๋ฏธํ„ฐ๋กœ Pageable ์„ ์ถ”๊ฐ€ํ•˜๋ฉด ๋œ๋‹ค.

 

๊ทธ๋Ÿผ ํŽ˜์ด์ง• ๊ด€๋ จ ์ฟผ๋ฆฌ๊ฐ€ ๋‚˜์˜จ๋‹ค.

 

Springboot ๋‚ด๋ถ€์—์„œ url ํŒŒ๋ผ๋ฏธํ„ฐ๊ฐ€ ์ปจํŠธ๋กค๋Ÿฌ์— ๋ฐ”์ธ๋”ฉ์ด ๋  ๋•Œ, Pageable์ด ์กด์žฌํ•˜๋ฉด PageRequest ๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ•œ๋‹ค.

 

ํ•ด๋‹น ๊ฐ์ฒด์—์„œ ์—ญ์‹œ ์ •๋ ฌ๋„ ์ œ๊ณตํ•˜๋Š”๋ฐ, url์„ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์น˜๋ฉด ์ •๋ ฌ๊ณผ ํŽ˜์ด์ง•์ด ๋™์‹œ์— ์ˆ˜ํ–‰๋˜๊ฒŒ ํ•  ์ˆ˜ ์žˆ๋‹ค.

 

  • http://localhost:8080/members?page=0
    • 0๋ฒˆ ํŽ˜์ด์ง€ ๋ถ€ํ„ฐ 20๊ฐœ ์กฐํšŒํ•œ๋‹ค.
      • default ๊ฐ€ 20๊ฐœ๋กœ default๋ฅผ ์ˆ˜์ •ํ•˜๋Š” ๋ฐฉ๋ฒ•๋„ ์กด์žฌํ•œ๋‹ค.
  • http://localhost:8080/members?page=0&size=5
    • 0๋ฒˆ ํŽ˜์ด์ง€๋ถ€ํ„ฐ 5๊ฐœ ์กฐํšŒํ•œ๋‹ค.
  • http://localhost:8080/members?page=0&size=5&sort=id.desc
    • 0๋ฒˆ ํŽ˜์ด์ง€๋ถ€ํ„ฐ 5๊ฐœ ์กฐํšŒ ํ•˜๋Š”๋ฐ, id์˜ ์—ญ์ˆœ์œผ๋กœ ์กฐํšŒํ•œ๋‹ค.

์ด๋ ‡๊ฒŒ ์˜ค๋Š˜์€ JPA ํŽ˜์ด์ง•์— ๋Œ€ํ•œ ๊ธฐ๋ณธ์„ ์•Œ์•„๋ณด์•˜๋‹ค.

 

๋‚ด์ผ์€ ์šฐ๋ฆฌ์˜ ๋งˆ์ง€๋ง‰ ์—ฌ์ •์ธ JPA Auditing ์— ๋Œ€ํ•ด์„œ ์•Œ์•„๋ณผ ๊ฒƒ์ด๋‹ค!

๋Œ“๊ธ€