Skip to content

Commit

Permalink
Commit iniziale
Browse files Browse the repository at this point in the history
  • Loading branch information
fpaparoni committed Mar 24, 2017
1 parent 5dd1419 commit 2236462
Show file tree
Hide file tree
Showing 4 changed files with 152 additions and 0 deletions.
51 changes: 51 additions & 0 deletions pom.xml
@@ -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>
@@ -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 src/main/java/com/javastaff/spring/boot/restjpa/Articolo.java
@@ -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;
}
}
@@ -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();

}

0 comments on commit 2236462

Please sign in to comment.