inblog logo
|
jay0628
    SpringBoot

    [Spring Boot] 26. 스프링부트 뱅크 v1 (8) 계좌 생성

    김주희's avatar
    김주희
    Mar 25, 2025
    [Spring Boot] 26. 스프링부트 뱅크 v1 (8) 계좌 생성
    Contents
    0. AccountResponse.ListDTO 사용한다면
     

    0. AccountResponse.ListDTO 사용한다면

     
    나중에 프론트를 고려한다면 ㄱㅊ은 방법이긴 한데 선생님 풀이에서는 그냥 프론트에서 number와 balance만 뽑아쓰는 방식
    내가 짠 repository
    public List<AccountResponse.ListDTO> findById(int userId) { List<AccountResponse.ListDTO> accountList = new ArrayList<>(); Query query = em.createNativeQuery("select number, balance from account_tb where user_id = ?"); query.setParameter(1, userId); List<Object[]> obsList = (List<Object[]>) query.getResultList(); for (Object[] obs : obsList) { AccountResponse.ListDTO list = new AccountResponse.ListDTO( (int) obs[0], (int) obs[1]); accountList.add(list); } return accountList; }
     
    Share article

    jay0628

    RSS·Powered by Inblog