|
|
|
@ -19,13 +19,9 @@ package sample.data.mongo;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.boot.CommandLineRunner;
|
|
|
|
|
import org.springframework.boot.SpringApplication;
|
|
|
|
|
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
|
|
|
|
import org.springframework.context.annotation.ComponentScan;
|
|
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
|
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|
|
|
|
|
|
|
|
|
@Configuration
|
|
|
|
|
@EnableAutoConfiguration
|
|
|
|
|
@ComponentScan
|
|
|
|
|
@SpringBootApplication
|
|
|
|
|
public class SampleMongoApplication implements CommandLineRunner {
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
@ -34,16 +30,16 @@ public class SampleMongoApplication implements CommandLineRunner {
|
|
|
|
|
@Override
|
|
|
|
|
public void run(String... args) throws Exception {
|
|
|
|
|
|
|
|
|
|
repository.deleteAll();
|
|
|
|
|
this.repository.deleteAll();
|
|
|
|
|
|
|
|
|
|
// save a couple of customers
|
|
|
|
|
repository.save(new Customer("Alice", "Smith"));
|
|
|
|
|
repository.save(new Customer("Bob", "Smith"));
|
|
|
|
|
this.repository.save(new Customer("Alice", "Smith"));
|
|
|
|
|
this.repository.save(new Customer("Bob", "Smith"));
|
|
|
|
|
|
|
|
|
|
// fetch all customers
|
|
|
|
|
System.out.println("Customers found with findAll():");
|
|
|
|
|
System.out.println("-------------------------------");
|
|
|
|
|
for (Customer customer : repository.findAll()) {
|
|
|
|
|
for (Customer customer : this.repository.findAll()) {
|
|
|
|
|
System.out.println(customer);
|
|
|
|
|
}
|
|
|
|
|
System.out.println();
|
|
|
|
@ -51,11 +47,11 @@ public class SampleMongoApplication implements CommandLineRunner {
|
|
|
|
|
// fetch an individual customer
|
|
|
|
|
System.out.println("Customer found with findByFirstName('Alice'):");
|
|
|
|
|
System.out.println("--------------------------------");
|
|
|
|
|
System.out.println(repository.findByFirstName("Alice"));
|
|
|
|
|
System.out.println(this.repository.findByFirstName("Alice"));
|
|
|
|
|
|
|
|
|
|
System.out.println("Customers found with findByLastName('Smith'):");
|
|
|
|
|
System.out.println("--------------------------------");
|
|
|
|
|
for (Customer customer : repository.findByLastName("Smith")) {
|
|
|
|
|
for (Customer customer : this.repository.findByLastName("Smith")) {
|
|
|
|
|
System.out.println(customer);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|