update sample code to use version 2.0.1 (#44)

* update sample code to use version 2.0.1

* add annotation hint in readme
This commit is contained in:
weiping 2018-03-09 13:01:35 +08:00 коммит произвёл GitHub
Родитель c3ebd4a335
Коммит 953581a909
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
5 изменённых файлов: 18 добавлений и 8 удалений

Просмотреть файл

@ -97,7 +97,7 @@ public class AppConfiguration extends AbstractDocumentDbConfiguration {
```
### Define en entity
### Define an entity
Define a simple entity as Document in DocumentDB.
```
@ -111,6 +111,8 @@ public class User {
... // setters and getters
public User() {
// If you do not want to create a default constructor,
// use annotation @JsonCreator and @JsonProperty in the full args constructor
}
public User(String id, String firstName, String lastName) {

Просмотреть файл

@ -7,7 +7,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.4.RELEASE</version>
<version>2.0.0.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
@ -45,7 +45,7 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<spring.data.documentdb.version>0.1.3</spring.data.documentdb.version>
<spring.data.documentdb.version>2.0.1</spring.data.documentdb.version>
</properties>
<dependencies>

Просмотреть файл

@ -28,20 +28,22 @@ public class SampleApplication implements CommandLineRunner {
SpringApplication.run(SampleApplication.class, args);
}
public void run(String... var1) throws Exception {
public void run(String... var1) {
final User testUser = new User("test@test.com", "testFirstName", "testLastName");
repository.deleteAll();
repository.save(testUser);
final User result1 = repository.findOne(testUser.getEmailAddress(), testUser.getLastName());
final List<User> results = repository.findByEmailAddressAndLastName(testUser.getEmailAddress(), testUser.getLastName());
Assert.isTrue(results.size() == 1, "Result size should be 1");
final User result1 = results.get(0);
Assert.state(result1.getFirstName().equals(testUser.getFirstName()), "query result firstName doesn't match!");
Assert.state(result1.getLastName().equals(testUser.getLastName()), "query result lastName doesn't match!");
LOGGER.info("findOne in User collection get result: {}", result1.toString());
System.out.println("findOne in User collection get result:" + result1.toString());
LOGGER.info("findByEmailAddressAndLastName in User collection get result: {}", result1.toString());
System.out.println("findByEmailAddressAndLastName in User collection get result:" + result1.toString());
final List<User> result2 = repository.findByFirstName(testUser.getFirstName());

Просмотреть файл

@ -6,6 +6,8 @@
package com.microsoft.azure.sample;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.microsoft.azure.spring.data.documentdb.core.mapping.Document;
import com.microsoft.azure.spring.data.documentdb.core.mapping.PartitionKey;
import org.springframework.data.annotation.Id;
@ -18,7 +20,9 @@ public class User {
@PartitionKey
private String lastName;
public User(String emailAddress, String firstName, String lastName) {
@JsonCreator
public User(@JsonProperty("emailAddress") String emailAddress, @JsonProperty("firstName") String firstName,
@JsonProperty("lastName") String lastName) {
this.emailAddress = emailAddress;
this.firstName = firstName;
this.lastName = lastName;

Просмотреть файл

@ -16,5 +16,7 @@ public interface UserRepository extends DocumentDbRepository<User, String> {
List<User> findByFirstName(String firstName);
List<User> findByLastName(String lastName);
List<User> findByEmailAddressAndLastName(String emailAddress, String lastName);
}