프로젝트

26. 선수 조회(몸값)

uni5948 2022. 1. 8. 15:08

26. 선수 조회(몸값)

  • 선수 저장소에 쿼리문 작성
    //몸값 별 선수 조회(내림차순)
    @Query(value = "SELECT * FROM PLAYER ORDER BY PLAYERPRICE DESC", nativeQuery = true)
    public List<Player> queryListPlayerDESC(Pageable pageable);

    //몸값 별 선수 조회(오름차순)
    @Query(value = "SELECT * FROM PLAYER ORDER BY PLAYERPRICE", nativeQuery = true)
    public List<Player> queryListPlayerASC(Pageable pageable);
 
  • 선수 서비스에 선수 조회 생성
1. PlayerService
    //몸값 별 선수 조회(내림차순)
    public List<Player> getPlayerALLpriceDESC(Pageable pageable);

    //몸값 별 선수 조회(오름차순)
    public List<Player> getPlayerALLpriceASC(Pageable pageable);
 
2. PlayerServiceImpl
 
    //몸값 별 선수 조회(내림차순)
    @Override
    public List<Player> getPlayerALLpriceDESC(Pageable pageable) {
        return pRepositoy.queryListPlayerDESC(pageable);
    }

    //몸값 별 선수 조회(오름차순)
    @Override
    public List<Player> getPlayerALLpriceASC(Pageable pageable) {
        return pRepositoy.queryListPlayerASC(pageable);
    }
  • 선수 조회 생성(PlayerController)

1. 몸 값 내림차순 조회

   
    //몸값 별 선수 조회(내림차순)
    //127.0.0.1:8080/REST/playerpricedesc?page=1
    @RequestMapping(value = "/playerpricedesc", method = {RequestMethod.GET},
    consumes = MediaType.ALL_VALUE,
    produces = MediaType.APPLICATION_JSON_VALUE)
    public Map<String, Object> playerpricedescGET(Player player,
    @RequestParam(value = "page", defaultValue = "1")int page ) {
        //페이지 네이션 처리
        PageRequest pageable = PageRequest.of(page-1, 15);
        Map<String, Object> map = new HashMap<>();
        try{
            List<Player> PlayerALLpriceDESC = pService.getPlayerALLpriceDESC(pageable);
            map.put("status", "200");
            map.put("count", PlayerALLpriceDESC.size());
            map.put("player", PlayerALLpriceDESC);
        }
        catch(Exception e){
            e.printStackTrace();
            map.put("status", e.hashCode());
        }
        return map;
    }

2. 몸 값 오름차순 조회


    //몸값 별 선수 조회(오름차순)
    //127.0.0.1:8080/REST/playerpriceasc
    @RequestMapping(value = "/playerpriceasc", method = {RequestMethod.GET},
    consumes = MediaType.ALL_VALUE,
    produces = MediaType.APPLICATION_JSON_VALUE)
    public Map<String, Object> playerpriceascGET(Player player,
    @RequestParam(value = "page", defaultValue = "1")int page  ) {
        //페이지 네이션 처리
        PageRequest pageable = PageRequest.of(page-1, 15);
        Map<String, Object> map = new HashMap<>();
        try{
            List<Player> PlayerALLpriceASC = pService.getPlayerALLpriceASC(pageable);
            map.put("status", "200");
            map.put("player", PlayerALLpriceASC);
        }
        catch(Exception e){
            e.printStackTrace();
            map.put("status", e.hashCode());
        }
        return map;
    }
  • 조회하기

1. 등록된 선수 몸 값 확인

등록된 선수 몸 값 확인

2. 몸 값 내림차순 조회

몸 값 내림차순 조회

3. 몸 값 오름차순 조회

몸 값 오름차순 조회

'프로젝트' 카테고리의 다른 글

28. vue 생성(spring 연동)  (0) 2022.01.10
27. 선수 조회(포지션)  (0) 2022.01.08
25. 스카우트 중복 조회  (0) 2022.01.07
24. 계약  (0) 2022.01.07
23. 스카우터 목록 삭제  (0) 2022.01.06