<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> <version>2.4.3</version> </dependency>
@NoRepositoryBean public interface ReadOnlyRepository<T, ID> extends Repository<T, ID> { Optional<T> findById(ID id); List<T> findAll(); }
@Entity public class Book { @Id @GeneratedValue private Long id; private String author; private String title; //getters and setters }
public interface BookReadOnlyRepository extends ReadOnlyRepository<Book, Long> { List<Book> findByAuthor(String author); List<Book> findByTitle(String title); }
猜你喜欢
本站原创《复杂软件设计之道:领域驱动设计全面解析与实战》
其他人在看