src/main/java/de/gedoplan/seminar/jpa/exercise/domain/Highway.java
@@ -1,11 +1,23 @@ package de.gedoplan.seminar.jpa.exercise.domain; import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.Table; @Entity @Table(name = Highway.TABLE_NAME) public class Highway { public static final String TABLE_NAME = "JPA_HIGHWAY"; @Id private int id; private String name; private String origin; private String destination; public Highway() { } public Highway(int id, String name, String origin, String destination) { this.id = id; @@ -46,6 +58,9 @@ return this.destination; } @Override public String toString() { return "Highway [id=" + id + ", name=" + name + ", origin=" + origin + ", destination=" + destination + "]"; } } src/main/java/de/gedoplan/seminar/jpa/exercise/repository/HighwayRepository.java
@@ -1,5 +1,11 @@ package de.gedoplan.seminar.jpa.exercise.repository; public interface HighwayRepository { import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; import de.gedoplan.seminar.jpa.exercise.domain.Highway; @Repository public interface HighwayRepository extends JpaRepository<Highway, Integer> { } src/main/java/de/gedoplan/seminar/jpa/exercise/rest/HighwayResource.java
@@ -38,7 +38,7 @@ public void insert(@RequestBody Highway highway) { this.logger.debug("----- insert -----"); // this.highwayRepository. this.highwayRepository.save(highway); this.logger.debug("Inserted: " + highway); } @@ -49,7 +49,7 @@ @GetMapping("/{ID}") public Highway findById(@PathVariable("ID") Integer id) { this.logger.debug("----- findById -----"); Optional<Highway> highway = Optional.empty();//this.highwayRepository. Optional<Highway> highway = this.highwayRepository.findById(id); highway.ifPresent(h -> this.logger.debug(id+": "+h)); return highway.orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND));