본문 바로가기

반응형

⭐🌏 JPA

(8)
No results were returned by the query. 해결하기 # No results were returned by the query. 발생 시 해결방법 - 이전에 JPA에서 오류나서 처리한 내역은 아래와 같다. 처리 내용도 아래와 같다. 중복이다...ㅋㅋ 2022.08.26 - [⭐🌏 JPA/🌏 Spring Error] - [ERROR] No results were returned by the query. [ERROR] No results were returned by the query. # No results were returned by the query. 해결방법에 대해서 알아보자. 내용은 쿼리에대한 반환값이 없다는 내용이다. - 해결방법 (제대로된 해결인지는 모르겠다.) - 반환값을 int로 받는다. 1. Controller /**.. may9noy.tis..
QueryDSL [SELECT * FROM TABLE] # QueryDSL을 활용하여 SELECT * FROM TABLE; 쿼리를 조회 후 결과값을 받아보자. 1. 프로세스 설명 컨트롤러에 호출 가능한 URL 생성 → 서비스 생성 → 조회 (Postman, 웹브라우저) 2. 컨트롤러 생성 /** BoardQuerydslRepository 에서 값을 가져오기 */ @GetMapping("/QueryDSL_findAllTest") public GeneralResponse QueryDSL_findAllTest() { return boardService.QueryDSL_findAllTest(); } 3. 서비스 생성 public GeneralResponse QueryDSL_findAllTest() { QBoardEntity m = QBoardEntity.boardE..
QueryDSL 설정방법 # 참고 블로그 https://highright96.tistory.com/32 [Querydsl] 스프링 부트에 Querydsl 설정하기 build.Gradle에 Querydsl 설정 추가 플러그인 추가 plugins { ... id "com.ewerk.gradle.plugins.querydsl" version "1.0.10" ... } 의존성 추가 dependencies { ... implementation 'com.querydsl:querydsl-jpa'.. highright96.tistory.com # QueryDSL 설정하기 - JPA, JPQL 쓰다보니 한가지 문제점이 간단한 CRUD는 문제없이 가능하지만 JOIN...하는게 너무 복잡하고 어려웠다. 물론 통계자료 같은 복잡한 쿼리는 네이티브 쿼..
[ERROR] No results were returned by the query. # No results were returned by the query. 해결방법에 대해서 알아보자. 내용은 쿼리에대한 반환값이 없다는 내용이다. - 해결방법 (제대로된 해결인지는 모르겠다.) - 반환값을 int로 받는다. 1. Controller /** 회원가입 정보 INSERT - NativeQuery */ @PostMapping("/joinMembershipNative") public GeneralResponse joinMembershipNative(@RequestParam(value = "id") Long id, @RequestParam(value = "description") String description, @RequestParam(value = "title") String title) { ..
[JPQL] 전체 테이블 검색 (SELECT * FROM TABLE) # 테이블의 전체 데이터를 가져오기 1. 컨트롤러 /** 전체 테이블 리스트를 가져오기 */ @GetMapping("/gr_jpql_all") public GeneralResponse gr_jpql_all() { return boardService.gr_jpql_all(); } 2. 서비스 public GeneralResponse gr_jpql_all() { List boardEntityList = boardRepository.gr_jpql_all(); System.out.println("값을 테스트 합니다" + boardEntityList); return GeneralResponse.builder() .status(true) .message("get all") .data(boardEntityList) ..
[JPQL] Like 쿼리를 활용한 검색 # JPQL을 활용하여 like 쿼리를 활용한 검색을 해보자. 1. 컨트롤러 /**김승현 이라는 이름을 like 조회로 조회하기*/ @GetMapping("/search_like") public GeneralResponse search_like(@RequestParam(value = "description") String description) { return boardService.search_like(description); } 2. 서비스 public GeneralResponse search_like(String description) { List boardEntityList = boardRepository.search_like(description); System.out.println("값을 테스..
Native Query를 통한 API 개발하기 [SELECT * FROM WHERE = {}] # Natice Query에 대한 단상 Springboot에서 네이티브 쿼리를 통한 개발을 해야할때가 간혹? 있다. 아니 솔직히 네이티브 쿼리로 개발하고 싶다. 왜냐하면 편하니까... 하지만 현재 개발자들이 네이티브 쿼리를 지향하고 있는 이유는 DB 및 테이블에 종속된다는 단점이 가장 큰거같다. # 하지만 장점은 퍼포먼스 차원에서 생각해 볼때 네이티브 쿼리가 훨씬 빠르다. 아래의 실험 결과를 보면, 네이티브 쿼리가 퍼포먼스 측면에서 훨씬 빠르다. https://stackoverflow.com/questions/60412667/performance-of-native-sql-query-and-jpa
JPQL을 이용한 API 개발하기 [SELECT * FROM WHERE ={}] 1. 컨트롤러에 api 생성하기 // JPQL을 용한 쿼리조회 @GetMapping("/jpql_title") public List jpql_title(@RequestParam(value = "title") String title) { return boardService.jpql_title(title); } - @GetMapping("/jpql_title") → 외부에서 url 호출 시 사용하는 주소값이다. - public List jpql_title(@RequestParam(value = "title") String title) { → 외부 url에서 호출할때 아래와 같이 파라미터 값을 부여하여 호출해야 한다. 한마디로 title이라는 외부 인자값을 가지고 수행한다고 볼 수 있다. (예시 : http:..

728x90
반응형