Add code from article (#10552)
This commit is contained in:
+39
@@ -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;
|
||||
}
|
||||
}
|
||||
+10
@@ -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);
|
||||
}
|
||||
+15
@@ -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();
|
||||
}
|
||||
+12
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user