Update for Spring Boot 2.0
This commit is contained in:
@@ -20,6 +20,8 @@ import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
@@ -74,6 +76,10 @@ class Employee implements Identifiable<Long> {
|
||||
this.role = role;
|
||||
}
|
||||
|
||||
public Optional<Long> getId() {
|
||||
return Optional.ofNullable(this.id);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will create another piece of data in the REST resource representation. These types
|
||||
* of methods are key in supporting backward compatibility.
|
||||
|
||||
@@ -70,8 +70,11 @@ class EmployeeController {
|
||||
*/
|
||||
@GetMapping(value = "/employees/{id}", produces = MediaTypes.HAL_JSON_VALUE)
|
||||
public ResponseEntity<Resource<Employee>> findOne(@PathVariable long id) {
|
||||
return ResponseEntity.ok(
|
||||
assembler.toResource(repository.findOne(id)));
|
||||
|
||||
return repository.findById(id)
|
||||
.map(assembler::toResource)
|
||||
.map(ResponseEntity::ok)
|
||||
.orElse(ResponseEntity.notFound().build());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user