diff --git a/README.md b/README.md index 977db51fd..686119af9 100644 --- a/README.md +++ b/README.md @@ -29,19 +29,13 @@ For those in a hurry: * Download the jar through Maven: - - org.springframework.data - spring-data-mongodb - 1.2.0.BUILD-SNAPSHOT - - - - - spring-maven-snapshot - true - Springframework Maven SNAPSHOT Repository - http://maven.springframework.org/snapshot - +```xml + + org.springframework.data + spring-data-mongodb + 1.2.1.RELEASE + +``` ### MongoTemplate MongoTemplate is the central support class for Mongo database operations. It provides @@ -54,93 +48,98 @@ Future plans are to support optional logging and/or exception throwing based on ### Easy Data Repository generation -To simplify the creation of Data Repositories a generic Repository interface and default implementation is provided. Furthermore, Spring will automatically create a Repository implementation for you that adds implementations of finder methods you specify on an interface. +To simplify the creation of data repositories a generic `Repository` interface and default implementation is provided. Furthermore, Spring will automatically create a Repository implementation for you that adds implementations of finder methods you specify on an interface. The Repository interface is - public interface Repository { - - T save(T entity); +```java +public interface Repository { - List save(Iterable entities); + T save(T entity); - T findById(ID id); + List save(Iterable entities); - boolean exists(ID id); + T findById(ID id); - List findAll(); + boolean exists(ID id); - Long count(); + List findAll(); - void delete(T entity); + Long count(); - void delete(Iterable entities); + void delete(T entity); - void deleteAll(); - } + void delete(Iterable entities); + void deleteAll(); +} +``` -The MongoRepository extends Repository and will in future add more Mongo specific methods. - public interface MongoRepository extends - Repository { - } +The `MongoRepository` extends `Repository` and will in future add more Mongo specific methods. -SimpleMongoRepository is the out of the box implementation of the MongoRepository you can use for basid CRUD operations. +```java +public interface MongoRepository extends Repository { +} +``` -To go beyond basic CRUD, extend the MongoRepository interface and supply your own finder methods that follow simple naming conventions such that they can be easily converted into queries. +`SimpleMongoRepository` is the out of the box implementation of the `MongoRepository` you can use for basid CRUD operations. -For example, given a Person class with first and last name properties, a PersonRepository interface that can query for Person by last name and when the first name matches a regular expression is shown below +To go beyond basic CRUD, extend the `MongoRepository` interface and supply your own finder methods that follow simple naming conventions such that they can be easily converted into queries. - public interface PersonRepository extends MongoRepository { +For example, given a `Person` class with first and last name properties, a `PersonRepository` interface that can query for `Person` by last name and when the first name matches a regular expression is shown below - List findByLastname(String lastname); +```java +public interface PersonRepository extends MongoRepository { - List findByFirstnameLike(String firstname); - } + List findByLastname(String lastname); -You can have Spring automatically generate the implemention as shown below + List findByFirstnameLike(String firstname); +} +``` - - - - - - - - - - +You can have Spring automatically create a proxy for the interface as shown below: - - - - +```xml + + + + + + + + + + -This will register an object in the container named PersonRepository. You can use it as shown below + +``` - @Service - public class MyService { +This will find the repository interface and register a proxy object in the container. You can use it as shown below: - @Autowired - PersonRepository repository; +``java +@Service +public class MyService { + @Autowired + private final PersonRepository repository; - public void doWork() { + public void doWork() { - repository.deleteAll(); + repository.deleteAll(); - Person person = new Person(); - person.setFirstname("Oliver"); - person.setLastname("Gierke"); - person = repository.save(person); + Person person = new Person(); + person.setFirstname("Oliver"); + person.setLastname("Gierke"); + person = repository.save(person); - List lastNameResults = repository.findByLastname("Gierke"); + List lastNameResults = repository.findByLastname("Gierke"); - List firstNameResults = repository.findByFirstnameLike("Oli*"); + List firstNameResults = repository.findByFirstnameLike("Oli*"); - } - } + } +} +``` Contributing to Spring Data