From 306a5ca1b873abdcf930b5087c0b0bafb29335f9 Mon Sep 17 00:00:00 2001 From: Oliver Gierke Date: Thu, 21 Jul 2011 10:21:50 +0200 Subject: [PATCH] Enable syntax highlighting in readme.md. --- readme.md | 145 +++++++++++++++++++++++++++++------------------------- 1 file changed, 77 insertions(+), 68 deletions(-) diff --git a/readme.md b/readme.md index f527f1147..7c4d720d4 100644 --- a/readme.md +++ b/readme.md @@ -24,93 +24,102 @@ For more detailed questions, use the [forum](http://forum.springsource.org/forum ## Quick Start ## Download the jar though Maven: - - - org.springframework.data - spring-data-jpa - 1.0.0.BUILD-SNAPSHOT - +```xml + + org.springframework.data + spring-data-jpa + 1.0.0.BUILD-SNAPSHOT + - - spring-maven-snapshot - - true - - Springframework Maven SNAPSHOT Repository - http://maven.springframework.org/snapshot - + + spring-maven-snapshot + + true + + Springframework Maven SNAPSHOT Repository + http://maven.springframework.org/snapshot + +``` Also include your JPA persistence provider of choice (Hibernate, EclipseLink, OpenJpa). Setup basic Spring JPA configuration as well as Spring Data JPA repository support. - - +```xml + + - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + +``` Create an entity: - @Entity - public class User { +```java +@Entity +public class User { + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private Integer id; + private String firstname; + private String lastname; - @Id - @GeneratedValue(strategy = GenerationType.AUTO) - private Integer id; - private String firstname; - private String lastname; - - // Getters and setters - } + // Getters and setters +} +``` Create a repository interface in `com.acme.repositories`: - public interface UserRepository extends CrudRepository { - List findByLastname(String lastname); - } +```java +public interface UserRepository extends CrudRepository { + List findByLastname(String lastname); +} +``` Write a test client - @RunWith(SpringJUnit4TestRunner.class) - @ContextConfiguration("classpath:your-config-file.xml") - public class UserRepositoryIntegrationTest { +```java +@RunWith(SpringJUnit4TestRunner.class) +@ContextConfiguration("classpath:your-config-file.xml") +public class UserRepositoryIntegrationTest { - @Autowrired UserRepository repository; + @Autowrired UserRepository repository; - @Test - public void sampleTestCase() { - User dave = new User("Dave", "Matthews"); - repository.save(user); + @Test + public void sampleTestCase() { + User dave = new User("Dave", "Matthews"); + repository.save(user); - User carter = new User("Carter", "Beauford"); - repository.save(carter); + User carter = new User("Carter", "Beauford"); + repository.save(carter); - List result = repository.findByLastname("Matthews"); - assertThat(result.size(), is(1)); - assertThat(result, hasItem(dave)); - } - } + List result = repository.findByLastname("Matthews"); + assertThat(result.size(), is(1)); + assertThat(result, hasItem(dave)); + } +} +``` ## Contributing to Spring Data ##