Spring

    [Spring boot] JPA dirty checking 시행 시점

    [Spring boot] JPA dirty checking 시행 시점

    직접 @Transactional 어노테이션이 달린 메소드를 실행해보며 언제 db에 저장되는지 확인해보자 PostApiController.java @PostMapping("api/v1/post/{id}") public PostResponseDto update(@PathVariable Long id, @RequestBody PostUpdateRequestDto requestDto){ System.out.println("transaction 시작"); PostResponseDto dto= postService.update(id, requestDto); System.out.println("transaction 종료"); return dto; } PostService.java @Transactional publi..

    [Spring boot] swagger 기본 설정

    [Spring boot] swagger 기본 설정

    build.gradle dependencies에 다음 추가 dependencies { ... // swagger ui implementation 'io.springfox:springfox-boot-starter:3.0.0' implementation 'io.springfox:springfox-swagger-ui:3.0.0' } SwaggerConfig.java package com.example.simpleBoard; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import springfox.documentation.builders.ApiInfoBu..

    [Spring boot] 같은 url, 다른 parameter

    스프링 부트의 컨트롤러에서 같은 url을 사용할 경우, ambiguous mapping found 오류가 발생한다. 이를 해결하기 위해서는 아래와 같이 설정하면 된다. 같은 url 이더라도 parameter가 다르다면 그 사실을 Mapping annotation에 명시해주자. @GetMapping(value = "api/v1/post", params = "title") // 같은 url 다른 param은 Mapping의 params를 이용하면 겹치는 오류가 발생하지 않는다. public List findByTitle(@RequestParam(name = "title") String title) { return postService.findByTitle(title); } @GetMapping("api/v1..

    [JPA/hibernate] Parameter value [\] did not match expected type [~] 오류 해결방법

    [JPA/hibernate] Parameter value [\] did not match expected type [~] 오류 해결방법

    JPA 프로젝트에서 findByItemContaining 등 sql에서의 like 구문 실행 시 같은 method를 두 번 실행하게 되면 오류가 발생하는 상황이 있다. https://github.com/spring-projects/spring-data-jpa/issues/2472 Issue with spring-data "startingWith" and hibernate 5.6.7: Parameter value [\] did not match expected type [java.lang.String (n/ Hello, I am trying to fetch some entity using a “find all by property starting with” query which amount to a Cri..