Add code from article (#10552)

This commit is contained in:
Jordan Simpson
2021-03-14 15:18:13 -05:00
committed by GitHub
parent 18bd57a704
commit af0b504061
6 changed files with 132 additions and 0 deletions
@@ -0,0 +1,39 @@
package com.baeldung.boot.readonlyrepository;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
@Entity
public class Book
{
@Id
@GeneratedValue
private Long id;
private String author;
private String title;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
}
@@ -0,0 +1,10 @@
package com.baeldung.boot.readonlyrepository;
import java.util.List;
public interface BookReadOnlyRepository extends ReadOnlyRepository<Book, Long> {
List<Book> findByAuthor(String author);
List<Book> findByTitle(String title);
}
@@ -0,0 +1,15 @@
package com.baeldung.boot.readonlyrepository;
import org.springframework.data.repository.NoRepositoryBean;
import org.springframework.data.repository.Repository;
import java.util.List;
import java.util.Optional;
@NoRepositoryBean
public interface ReadOnlyRepository<T, ID> extends Repository<T, ID> {
Optional<T> findById(ID id);
List<T> findAll();
}
@@ -0,0 +1,12 @@
package com.baeldung.boot.readonlyrepository;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class ReadOnlyRepositoryApplication {
public static void main(String[] args) {
SpringApplication.run(ReadOnlyRepositoryApplication.class, args);
}
}