mirror of
https://github.com/OtusTeam/Spring.git
synced 2026-05-30 10:50:42 +00:00
spring-12, spring-12-mongo
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>ru.otus</groupId>
|
||||
<artifactId>spring-12-mongo</artifactId>
|
||||
<version>1.0</version>
|
||||
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<modules>
|
||||
<module>spring-12-mongo-exercise</module>
|
||||
<module>spring-12-mongo-solution</module>
|
||||
</modules>
|
||||
</project>
|
||||
@@ -0,0 +1,4 @@
|
||||
.idea/
|
||||
*.iml
|
||||
|
||||
target/
|
||||
@@ -0,0 +1,40 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>ru.otus</groupId>
|
||||
<artifactId>spring-framework-12-mongo</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.0.3.RELEASE</version>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-mongodb</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>de.flapdoodle.embed</groupId>
|
||||
<artifactId>de.flapdoodle.embed.mongo</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
package ru.otus.spring12;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.data.mongodb.repository.config.EnableMongoRepositories;
|
||||
import ru.otus.spring12.domain.Person;
|
||||
import ru.otus.spring12.repostory.PersonRepository;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
@SpringBootApplication
|
||||
public class Main {
|
||||
|
||||
@SuppressWarnings("SpringJavaAutowiredFieldsWarningInspection")
|
||||
@Autowired
|
||||
private PersonRepository repository;
|
||||
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
ApplicationContext context = SpringApplication.run(Main.class);
|
||||
|
||||
PersonRepository repository = context.getBean(PersonRepository.class);
|
||||
|
||||
repository.save(new Person("Pushkin"));
|
||||
|
||||
Thread.sleep(3000);
|
||||
|
||||
repository.findAll().forEach(p -> System.out.println(p.getName()));
|
||||
}
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
package ru.otus.spring12.domain;
|
||||
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
|
||||
public class Person {
|
||||
|
||||
private String id;
|
||||
private String name;
|
||||
|
||||
public Person(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
package ru.otus.spring12.repostory;
|
||||
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import ru.otus.spring12.domain.Person;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public interface PersonRepository extends CrudRepository<Person, Integer> {
|
||||
|
||||
List<Person> findAll();
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
spring:
|
||||
data:
|
||||
mongodb:
|
||||
database: company
|
||||
@@ -0,0 +1,4 @@
|
||||
.idea/
|
||||
*.iml
|
||||
|
||||
target/
|
||||
@@ -0,0 +1,46 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>ru.otus</groupId>
|
||||
<artifactId>spring-framework-12-mongo</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.0.3.RELEASE</version>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-mongodb</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>de.flapdoodle.embed</groupId>
|
||||
<artifactId>de.flapdoodle.embed.mongo</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.github.mongobee</groupId>
|
||||
<artifactId>mongobee</artifactId>
|
||||
<version>0.13</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
package ru.otus.spring12;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.data.mongodb.repository.config.EnableMongoRepositories;
|
||||
import ru.otus.spring12.domain.Person;
|
||||
import ru.otus.spring12.repostory.PersonRepository;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
@EnableMongoRepositories
|
||||
@SpringBootApplication
|
||||
public class Main {
|
||||
|
||||
@SuppressWarnings("SpringJavaAutowiredFieldsWarningInspection")
|
||||
@Autowired
|
||||
private PersonRepository repository;
|
||||
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
ApplicationContext context = SpringApplication.run(Main.class);
|
||||
|
||||
PersonRepository repository = context.getBean(PersonRepository.class);
|
||||
|
||||
repository.save(new Person("Pushkin"));
|
||||
|
||||
Thread.sleep(3000);
|
||||
|
||||
repository.findAll().forEach(p -> System.out.println(p.getName()));
|
||||
}
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
package ru.otus.spring12.bee;
|
||||
|
||||
import com.github.mongobee.Mongobee;
|
||||
import com.mongodb.MongoClient;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.env.Environment;
|
||||
import ru.otus.spring12.bee.changelog.DatabaseChangelog;
|
||||
|
||||
@Configuration
|
||||
public class MongoBeeConfig {
|
||||
|
||||
@Autowired
|
||||
private MongoClient mongo;
|
||||
|
||||
@Bean
|
||||
public Mongobee mongobee(Environment environment) {
|
||||
Mongobee runner = new Mongobee(mongo);
|
||||
runner.setDbName("company");
|
||||
runner.setChangeLogsScanPackage(DatabaseChangelog.class.getPackage().getName());
|
||||
runner.setSpringEnvironment(environment);
|
||||
return runner;
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
package ru.otus.spring12.bee.changelog;
|
||||
|
||||
import com.github.mongobee.changeset.ChangeLog;
|
||||
import com.github.mongobee.changeset.ChangeSet;
|
||||
import com.mongodb.BasicDBObject;
|
||||
import com.mongodb.DB;
|
||||
import com.mongodb.DBCollection;
|
||||
|
||||
@ChangeLog
|
||||
public class DatabaseChangelog {
|
||||
|
||||
@ChangeSet(order = "001", id = "addLermontov", author = "ydvorzhetskiy")
|
||||
public void insertLermontov(DB db) {
|
||||
DBCollection myCollection = db.getCollection("persons");
|
||||
BasicDBObject doc = new BasicDBObject().append("name", "Lermontov");
|
||||
myCollection.insert(doc);
|
||||
}
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
package ru.otus.spring12.domain;
|
||||
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
|
||||
@Document(collection = "persons")
|
||||
public class Person {
|
||||
|
||||
@Id
|
||||
private String id;
|
||||
private String name;
|
||||
|
||||
public Person(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
package ru.otus.spring12.repostory;
|
||||
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import ru.otus.spring12.domain.Person;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public interface PersonRepository extends CrudRepository<Person, Integer> {
|
||||
|
||||
List<Person> findAll();
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
spring:
|
||||
data:
|
||||
mongodb:
|
||||
database: company
|
||||
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>ru.otus</groupId>
|
||||
<artifactId>spring-12</artifactId>
|
||||
<version>1.0</version>
|
||||
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<modules>
|
||||
<module>spring-12-exercise</module>
|
||||
<module>spring-12-solution</module>
|
||||
</modules>
|
||||
</project>
|
||||
@@ -0,0 +1,4 @@
|
||||
.idea/
|
||||
*.iml
|
||||
|
||||
target/
|
||||
@@ -0,0 +1,37 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>ru.otus</groupId>
|
||||
<artifactId>spring-framework-12</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.0.3.RELEASE</version>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<!--<dependency>-->
|
||||
<!--<groupId>org.springframework.data</groupId>-->
|
||||
<!--<artifactId>spring-data-keyvalue</artifactId>-->
|
||||
<!--<version>2.0.9.RELEASE</version>-->
|
||||
<!--</dependency>-->
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
@@ -0,0 +1,29 @@
|
||||
package ru.otus.spring12;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.data.map.repository.config.EnableMapRepositories;
|
||||
import ru.otus.spring12.domain.Person;
|
||||
import ru.otus.spring12.repostory.PersonRepository;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
@SpringBootApplication
|
||||
public class Main {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(Main.class);
|
||||
}
|
||||
|
||||
@SuppressWarnings("SpringJavaAutowiredFieldsWarningInspection")
|
||||
@Autowired
|
||||
private PersonRepository repository;
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
repository.save(new Person("Pushkin"));
|
||||
|
||||
repository.findAll();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package ru.otus.spring12.domain;
|
||||
|
||||
public class Email {
|
||||
|
||||
private int id;
|
||||
|
||||
private String email;
|
||||
|
||||
public Email(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
package ru.otus.spring12.domain;
|
||||
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.keyvalue.annotation.KeySpace;
|
||||
|
||||
public class Person {
|
||||
|
||||
private int id;
|
||||
private String name;
|
||||
|
||||
public Person(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
package ru.otus.spring12.repostory;
|
||||
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import ru.otus.spring12.domain.Person;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface PersonRepository extends CrudRepository<Person, Integer> {
|
||||
|
||||
List<Person> findAll();
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
.idea/
|
||||
*.iml
|
||||
|
||||
target/
|
||||
@@ -0,0 +1,37 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>ru.otus</groupId>
|
||||
<artifactId>spring-framework-12</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.0.3.RELEASE</version>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.data</groupId>
|
||||
<artifactId>spring-data-keyvalue</artifactId>
|
||||
<version>2.0.9.RELEASE</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
@@ -0,0 +1,37 @@
|
||||
package ru.otus.spring12;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.data.map.repository.config.EnableMapRepositories;
|
||||
import ru.otus.spring12.domain.Email;
|
||||
import ru.otus.spring12.domain.Person;
|
||||
import ru.otus.spring12.repostory.EmailRepository;
|
||||
import ru.otus.spring12.repostory.PersonRepository;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
@SpringBootApplication
|
||||
@EnableMapRepositories
|
||||
public class Main {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(Main.class);
|
||||
}
|
||||
|
||||
@SuppressWarnings("SpringJavaAutowiredFieldsWarningInspection")
|
||||
@Autowired
|
||||
private PersonRepository repository;
|
||||
|
||||
@Autowired
|
||||
private EmailRepository emailRepository;
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
repository.save(new Person("Pushkin"));
|
||||
System.out.println(repository.findAll());
|
||||
|
||||
emailRepository.save(new Email("alex@pushkin.com"));
|
||||
System.out.println(emailRepository.findAll());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package ru.otus.spring12.domain;
|
||||
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.keyvalue.annotation.KeySpace;
|
||||
|
||||
@KeySpace("email")
|
||||
public class Email {
|
||||
@Id
|
||||
private int id;
|
||||
|
||||
private String email;
|
||||
|
||||
public Email(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Email{" +
|
||||
"id=" + id +
|
||||
", email='" + email + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
package ru.otus.spring12.domain;
|
||||
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.keyvalue.annotation.KeySpace;
|
||||
|
||||
@KeySpace("person")
|
||||
public class Person {
|
||||
|
||||
@Id
|
||||
private int id;
|
||||
private String name;
|
||||
|
||||
public Person(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Person{" +
|
||||
"id=" + id +
|
||||
", name='" + name + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
package ru.otus.spring12.repostory;
|
||||
|
||||
import org.springframework.data.keyvalue.repository.KeyValueRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import ru.otus.spring12.domain.Email;
|
||||
import ru.otus.spring12.domain.Person;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface EmailRepository {
|
||||
|
||||
List<Email> findAll();
|
||||
Email save(Email email);
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
package ru.otus.spring12.repostory;
|
||||
|
||||
import org.springframework.data.keyvalue.core.KeyValueOperations;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import ru.otus.spring12.domain.Email;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Repository
|
||||
public class EmailRepositoryImpl implements EmailRepository {
|
||||
|
||||
final private KeyValueOperations keyValueTemplate;
|
||||
|
||||
public EmailRepositoryImpl(KeyValueOperations keyValueTemplate) {
|
||||
this.keyValueTemplate = keyValueTemplate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Email> findAll() {
|
||||
return (List<Email>) keyValueTemplate.findAll(Email.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Email save(Email email) {
|
||||
return keyValueTemplate.insert(email);
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
package ru.otus.spring12.repostory;
|
||||
|
||||
import org.springframework.data.keyvalue.repository.KeyValueRepository;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import ru.otus.spring12.domain.Person;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface PersonRepository extends KeyValueRepository<Person, Integer> {
|
||||
|
||||
List<Person> findAll();
|
||||
}
|
||||
Reference in New Issue
Block a user