Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.clientbookserver.controller;
- import com.clientbookserver.model.Client;
- import com.clientbookserver.service.ClientService;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.http.MediaType;
- import org.springframework.web.bind.annotation.*;
- import java.util.List;
- @RestController
- public class ClientRestController {
- @Autowired
- ClientService clientService;
- @GetMapping(value = "/clients", produces = MediaType.APPLICATION_JSON_VALUE)
- public List<Client> getAllClients() {
- return clientService.findAll();
- }
- @PostMapping(value = "/clients")
- public Client saveClient(@RequestBody Client client) {
- return clientService.save(new Client(client.getFirstName(), client.getLastName()));
- }
- @GetMapping(value = "/clients/{lastName}", produces = MediaType.APPLICATION_JSON_VALUE)
- public List<Client> findClientByLastName(@PathVariable String lastName) {
- return clientService.findByLastName(lastName);
- }
- @DeleteMapping(value = "/clients/{id}")
- public void deleteClient(@PathVariable Integer id) {
- clientService.delete(id);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement