Advertisement
Guest User

controller

a guest
Sep 25th, 2017
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.16 KB | None | 0 0
  1. package com.clientbookserver.controller;
  2.  
  3. import com.clientbookserver.model.Client;
  4. import com.clientbookserver.service.ClientService;
  5. import org.springframework.beans.factory.annotation.Autowired;
  6. import org.springframework.http.MediaType;
  7. import org.springframework.web.bind.annotation.*;
  8.  
  9. import java.util.List;
  10.  
  11. @RestController
  12. public class ClientRestController {
  13.     @Autowired
  14.     ClientService clientService;
  15.  
  16.     @GetMapping(value = "/clients", produces = MediaType.APPLICATION_JSON_VALUE)
  17.     public List<Client> getAllClients() {
  18.         return clientService.findAll();
  19.     }
  20.  
  21.     @PostMapping(value = "/clients")
  22.     public Client saveClient(@RequestBody Client client) {
  23.         return clientService.save(new Client(client.getFirstName(), client.getLastName()));
  24.     }
  25.  
  26.     @GetMapping(value = "/clients/{lastName}", produces = MediaType.APPLICATION_JSON_VALUE)
  27.     public List<Client> findClientByLastName(@PathVariable String lastName) {
  28.         return clientService.findByLastName(lastName);
  29.     }
  30.  
  31.     @DeleteMapping(value = "/clients/{id}")
  32.     public void deleteClient(@PathVariable Integer id) {
  33.         clientService.delete(id);
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement