프로젝트

27. 선수 조회(포지션)

uni5948 2022. 1. 8. 20:47

27. 선수 조회(포지션)

  • 선수 저장소에 쿼리문 작성
    //포지션 별 선수 조회
    @Query(value = "SELECT * FROM PLAYER WHERE PLAYERPOSITION = :position", nativeQuery = true)
    public List<Player> queryListPlayerPosition(@Param("position") String position, Pageable pageable);
  • 선수 서비스에 선수 조회 생성
1. PlayerService
 
    //포지션 별 선수 조회
    public List<Player> getPlayerALLposition(String position, Pageable pageable);
 
2. PlayerServiceImpl
    //포지션 별 선수 조회
    @Override
    public List<Player> getPlayerALLposition(String position, Pageable pageable) {
        return pRepositoy.queryListPlayerPosition(position, pageable);
    }
 
  • 선수 조회 생성
    //포지션 별 선수 조회
    //127.0.0.1:8080/REST/playerposition?page=1&position=
    @RequestMapping(value = "/playerposition", method = {RequestMethod.GET},
    consumes = MediaType.ALL_VALUE,
    produces = MediaType.APPLICATION_JSON_VALUE)
    public Map<String, Object> playerpositionGET(Player player,
    @RequestParam(value = "page", defaultValue = "1")int page,
    @RequestParam(value = "position", defaultValue = "")String position) {
        //페이지 네이션 처리
        PageRequest pageable = PageRequest.of(page-1, 15);
        Map<String, Object> map = new HashMap<>();
        try{
            List<Player> PlayerPosition = pService.getPlayerALLposition(position, pageable);
            map.put("status", "200");
            map.put("player", PlayerPosition);
        }
        catch(Exception e){
            e.printStackTrace();
            map.put("status", e.hashCode());
        }
        return map;
    }
 
 
  • 조회하기

1. 등록된 선수 포지션 확인

등록된 선수 포지션 확인

2. 포지션 별 선수 조회

포지션 별 선수 조회

 

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

29. 회원 가입  (0) 2022.01.10
28. vue 생성(spring 연동)  (0) 2022.01.10
26. 선수 조회(몸값)  (0) 2022.01.08
25. 스카우트 중복 조회  (0) 2022.01.07
24. 계약  (0) 2022.01.07