Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
152 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>com.javastaff</groupId> | ||
<artifactId>spring.boot.restjpa</artifactId> | ||
<version>0.0.1</version> | ||
<packaging>war</packaging> | ||
|
||
<name>Esempio Spring Boot REST JPA</name> | ||
|
||
<parent> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-parent</artifactId> | ||
<version>1.5.2.RELEASE</version> | ||
</parent> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-web</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-data-rest</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-data-jpa</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.h2database</groupId> | ||
<artifactId>h2</artifactId> | ||
</dependency> | ||
</dependencies> | ||
|
||
<properties> | ||
<java.version>1.8</java.version> | ||
</properties> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-maven-plugin</artifactId> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
13 changes: 13 additions & 0 deletions
13
src/main/java/com/javastaff/spring/boot/restjpa/ApplicationStarter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.javastaff.spring.boot.restjpa; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
@SpringBootApplication | ||
public class ApplicationStarter { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(ApplicationStarter.class, args); | ||
} | ||
|
||
} |
56 changes: 56 additions & 0 deletions
56
src/main/java/com/javastaff/spring/boot/restjpa/Articolo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package com.javastaff.spring.boot.restjpa; | ||
|
||
import java.util.Date; | ||
import java.util.List; | ||
|
||
import javax.persistence.ElementCollection; | ||
import javax.persistence.Entity; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.GenerationType; | ||
import javax.persistence.Id; | ||
|
||
@Entity | ||
public class Articolo { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.AUTO) | ||
private long id; | ||
|
||
private String titolo; | ||
private String testo; | ||
private Date dataPubblicazione; | ||
|
||
@ElementCollection(targetClass=String.class) | ||
private List<String> taglist; | ||
|
||
public long getId() { | ||
return id; | ||
} | ||
public void setId(long id) { | ||
this.id = id; | ||
} | ||
public String getTitolo() { | ||
return titolo; | ||
} | ||
public void setTitolo(String titolo) { | ||
this.titolo = titolo; | ||
} | ||
public String getTesto() { | ||
return testo; | ||
} | ||
public void setTesto(String testo) { | ||
this.testo = testo; | ||
} | ||
public Date getDataPubblicazione() { | ||
return dataPubblicazione; | ||
} | ||
public void setDataPubblicazione(Date dataPubblicazione) { | ||
this.dataPubblicazione = dataPubblicazione; | ||
} | ||
public List<String> getTaglist() { | ||
return taglist; | ||
} | ||
public void setTaglist(List<String> taglist) { | ||
this.taglist = taglist; | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
src/main/java/com/javastaff/spring/boot/restjpa/ArticoloRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.javastaff.spring.boot.restjpa; | ||
|
||
import java.util.List; | ||
|
||
import org.springframework.data.repository.PagingAndSortingRepository; | ||
import org.springframework.data.repository.query.Param; | ||
import org.springframework.data.rest.core.annotation.RepositoryRestResource; | ||
import org.springframework.data.rest.core.annotation.RestResource; | ||
|
||
@RepositoryRestResource(collectionResourceRel = "articoli", path = "articoli") | ||
public interface ArticoloRepository extends PagingAndSortingRepository<Articolo, Long> { | ||
|
||
List<Articolo> findByTitolo(@Param("titolo") String titolo); | ||
List<Articolo> findByTaglistIn(@Param("tags") List<String> tags); | ||
|
||
@Override | ||
@RestResource(exported = false) | ||
void delete(Articolo articolo); | ||
|
||
@Override | ||
@RestResource(exported = false) | ||
void delete(Iterable<? extends Articolo> articoli); | ||
|
||
@Override | ||
@RestResource(exported = false) | ||
void delete(Long id); | ||
|
||
@Override | ||
@RestResource(exported = false) | ||
void deleteAll(); | ||
|
||
} |