From ce68b89c7b265e457711bd2fbe0e7a81e50a9b2c Mon Sep 17 00:00:00 2001 From: amedviediev Date: Sun, 28 Feb 2016 19:55:39 +0200 Subject: [PATCH] Added code for "Intro to Spring Data REST" artice --- spring-data-rest/pom.xml | 62 +++++++++++++++++++ .../baeldung/SpringDataRestApplication.java | 11 ++++ .../java/com/baeldung/UserRepository.java | 12 ++++ .../main/java/com/baeldung/WebsiteUser.java | 41 ++++++++++++ .../src/main/resources/application.properties | 0 5 files changed, 126 insertions(+) create mode 100644 spring-data-rest/pom.xml create mode 100644 spring-data-rest/src/main/java/com/baeldung/SpringDataRestApplication.java create mode 100644 spring-data-rest/src/main/java/com/baeldung/UserRepository.java create mode 100644 spring-data-rest/src/main/java/com/baeldung/WebsiteUser.java create mode 100644 spring-data-rest/src/main/resources/application.properties diff --git a/spring-data-rest/pom.xml b/spring-data-rest/pom.xml new file mode 100644 index 0000000000..ad2f9ceb2d --- /dev/null +++ b/spring-data-rest/pom.xml @@ -0,0 +1,62 @@ + + + 4.0.0 + + com.baeldung + intro-spring-data-rest + 0.0.1-SNAPSHOT + jar + + intro-spring-data-rest + Intro to Spring Data REST + + + org.springframework.boot + spring-boot-starter-parent + 1.3.3.RELEASE + + + + + UTF-8 + 1.8 + + + + + org.springframework.boot + spring-boot-starter + + + + org.springframework.boot + spring-boot-starter-data-rest + + + org.springframework.boot + spring-boot-starter-data-jpa + + + com.h2database + h2 + + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + + diff --git a/spring-data-rest/src/main/java/com/baeldung/SpringDataRestApplication.java b/spring-data-rest/src/main/java/com/baeldung/SpringDataRestApplication.java new file mode 100644 index 0000000000..6e8e62f52c --- /dev/null +++ b/spring-data-rest/src/main/java/com/baeldung/SpringDataRestApplication.java @@ -0,0 +1,11 @@ +package com.baeldung; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class SpringDataRestApplication { + public static void main(String[] args) { + SpringApplication.run(SpringDataRestApplication.class, args); + } +} diff --git a/spring-data-rest/src/main/java/com/baeldung/UserRepository.java b/spring-data-rest/src/main/java/com/baeldung/UserRepository.java new file mode 100644 index 0000000000..ebbf0d49ab --- /dev/null +++ b/spring-data-rest/src/main/java/com/baeldung/UserRepository.java @@ -0,0 +1,12 @@ +package com.baeldung; + +import org.springframework.data.repository.PagingAndSortingRepository; +import org.springframework.data.repository.query.Param; +import org.springframework.data.rest.core.annotation.RepositoryRestResource; + +import java.util.List; + +@RepositoryRestResource(collectionResourceRel = "users", path = "users") +public interface UserRepository extends PagingAndSortingRepository { + List findByName(@Param("name") String name); +} diff --git a/spring-data-rest/src/main/java/com/baeldung/WebsiteUser.java b/spring-data-rest/src/main/java/com/baeldung/WebsiteUser.java new file mode 100644 index 0000000000..a7a35a2573 --- /dev/null +++ b/spring-data-rest/src/main/java/com/baeldung/WebsiteUser.java @@ -0,0 +1,41 @@ +package com.baeldung; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; + +@Entity +public class WebsiteUser { + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private long id; + + private String name; + private String email; + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } +} diff --git a/spring-data-rest/src/main/resources/application.properties b/spring-data-rest/src/main/resources/application.properties new file mode 100644 index 0000000000..e69de29bb2