/
spirzen
/
it-code-examples
Обзор
Документация
Войти
/
spirzen
/
it-code-examples
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
examples/java/java-503-254-004/main.java
55 строк
2 KB
Spirzen
Code migration pack
09 июн 2026, 01:41
09 июн 2026, 01:41
cebc284
Код
Авторство
О чём код?
package com.example.crm.controller; import com.example.crm.model.Customer; import com.example.crm.service.CustomerService; import jakarta.validation.Valid; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.bind.annotation.RestController; import java.util.List; @RestController @RequestMapping("/api/customers") public class CustomerRestController { private final CustomerService customerService; public CustomerRestController(CustomerService customerService) { this.customerService = customerService; } @GetMapping public List<Customer> getAll() { return customerService.findAll(); } @GetMapping("/{id}") public Customer getById(@PathVariable Long id) { return customerService.findById(id); } @PostMapping @ResponseStatus(HttpStatus.CREATED) public Customer create(@Valid @RequestBody Customer customer) { return customerService.create(customer); } @PutMapping("/{id}") public Customer update(@PathVariable Long id, @Valid @RequestBody Customer customer) { return customerService.update(id, customer); } @DeleteMapping("/{id}") @ResponseStatus(HttpStatus.NO_CONTENT) public void delete(@PathVariable Long id) { customerService.delete(id); } }