Commit 04e76a9f by Patryk Czarnik

Namiasta REST / JSON

parent 216f7078
package alx.data;
import alx.model.Location;
import org.springframework.data.jpa.repository.JpaRepository;
public interface LocationRespository extends JpaRepository<Location, Integer> {
}
......@@ -7,16 +7,16 @@ import java.util.stream.Collectors;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import alx.model.Employee;
@Repository
public interface Repository5 extends JpaRepository<Employee, Integer> {
List<Employee> findByLastName(String name);
List<Employee> findByLastNameContainingIgnoringCase(String name);
List<Employee> findBySalaryBetween(BigDecimal min, BigDecimal max);
List<Employee> findByJob_JobId(String jobId);
......
package alx.rest;
import alx.data.LocationRespository;
import alx.model.Location;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.server.ResponseStatusException;
import java.util.List;
@RestController
@RequestMapping("/locations")
public class LocationsJson {
@Autowired
private LocationRespository repo;
@GetMapping
public List<Location> readAll() {
return repo.findAll();
}
@GetMapping("/{id}")
public Location readOne(@PathVariable Integer id) {
return repo.findById(id).orElseThrow(() -> new ResponseStatusException(
HttpStatus.NOT_FOUND, "Location Not Found"));
}
}
......@@ -83,5 +83,11 @@
<p>Pisane <a th:href="@{/emps9}">TERAZ</a></p>
<h2>REST / JSON</h2>
<ul>
<li><a href="/locations">locations</a></li>
<li><a href="/locations/1200">locations/1200</a></li>
</ul>
</body>
</html>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment