반응형
CrudRepository # findOne 메서드 누락
내 프로젝트에서 Spring 5를 사용하고 있습니다. 오늘까지 사용 가능한 방법이있었습니다 CrudRepository#findOne
.
하지만 최신 스냅 샷을 다운로드 한 후 갑자기 사라졌습니다! 현재이 방법을 사용할 수 없다는 언급이 있습니까?
내 의존성 목록 :
apply plugin: 'java'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
repositories {
mavenCentral()
maven { url "https://repo.spring.io/snapshot" }
maven { url "https://repo.spring.io/milestone" }
}
dependencies {
compile 'org.springframework.boot:spring-boot-starter-validation'
compile 'org.springframework.boot:spring-boot-starter-web'
compile 'org.springframework.boot:spring-boot-starter-data-jpa'
runtime 'org.springframework.boot:spring-boot-devtools'
runtime 'com.h2database:h2:1.4.194'
compile 'org.projectlombok:lombok:1.16.14'
compile 'org.modelmapper:modelmapper:0.7.5'
testCompile 'org.springframework.boot:spring-boot-starter-test'
testCompile 'org.codehaus.groovy:groovy-all:2.4.10'
testCompile 'cglib:cglib:3.2.5'
testCompile 'org.spockframework:spock-core:1.0-groovy-2.4'
}
최신 정보:
이 방법이 다음으로 대체 된 것 같습니다. CrudRepository#findById
참조하시기 바랍니다 DATACMNS-944 에 연결되어 이 커밋 다음 이름 바꾸기를 가지고있는
╔═════════════════════╦═══════════════════════╗
║ Old name ║ New name ║
╠═════════════════════╬═══════════════════════╣
║ findOne(…) ║ findById(…) ║
╠═════════════════════╬═══════════════════════╣
║ save(Iterable) ║ saveAll(Iterable) ║
╠═════════════════════╬═══════════════════════╣
║ findAll(Iterable) ║ findAllById(…) ║
╠═════════════════════╬═══════════════════════╣
║ delete(ID) ║ deleteById(ID) ║
╠═════════════════════╬═══════════════════════╣
║ delete(Iterable) ║ deleteAll(Iterable) ║
╠═════════════════════╬═══════════════════════╣
║ exists() ║ existsById(…) ║
╚═════════════════════╩═══════════════════════╝
주 findById
에 대한 정확한 대체하지 않습니다는 findOne
, 그것은 반환 Optional
대신에 null
.
새로운 자바에 익숙하지 않아서 알아내는 데 약간의 시간이 걸렸지 만 이것은 findById
동작을 findOne
하나로 바꿉니다 .
return rep.findById(id).orElse(null);
We had many hundreds of usages of the old findOne()
method. Rather than embark on a mammoth refactor, we ended up creating the following intermediary interface and had our repositories extend it instead of extending JpaRepository
directly
@NoRepositoryBean
public interface BaseJpaRepository<T, ID> extends JpaRepository<T, ID> {
default T findOne(ID id) {
return (T) findById(id).orElse(null);
}
}
A pragmatic transform
Old way:
Entity aThing = repository.findOne(1L);
New way:
Optional<Entity> aThing = repository.findById(1L);
참고URL : https://stackoverflow.com/questions/44101061/missing-crudrepositoryfindone-method
반응형
'development' 카테고리의 다른 글
바이트 배열을 숫자 값 (Java)으로 변환하는 방법은 무엇입니까? (0) | 2020.09.17 |
---|---|
Android AlarmManager-RTC_WAKEUP 대 ELAPSED_REALTIME_WAKEUP (0) | 2020.09.17 |
경고 : 헤더 정보를 수정할 수 없습니다. 헤더는 이미 ERROR [duplicate]에 의해 전송되었습니다. (0) | 2020.09.17 |
Kafka 0.8.1.1에서 주제 삭제 (0) | 2020.09.17 |
Thymeleaf : 조건문을 사용하여 CSS 클래스를 동적으로 추가 / 제거하는 방법 (0) | 2020.09.17 |