/
pavelsamodurov
/
financejavaee216
Обзор
Документация
Войти
/
pavelsamodurov
/
financejavaee216
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
financejavaee-ejb/src/main/java/com/testproject/facade/CustomerFacadeRest.java
78 строк
2 KB
Pavel Samodurov
add CustomerFacadeREST
24 фев 2020, 11:55
24 фев 2020, 11:55
ea47b60
Код
Авторство
О чём код?
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package com.testproject.facade; import com.testproject.model.Customer; import java.util.List; import javax.ejb.EJB; import javax.ws.rs.Consumes; import javax.ws.rs.DELETE; import javax.ws.rs.GET; import javax.ws.rs.POST; import javax.ws.rs.PUT; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; /** * * @author Pavel Samodurov ps07t447@gmail.com */ @Path("/customer") public class CustomerFacadeRest { @EJB CustomerFacadeLocal customerFacade; @POST @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) public void create(Customer entity) { customerFacade.create(entity); } @PUT @Path("{id}") @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) public void edit(@PathParam("id") Integer id, Customer entity) { customerFacade.edit(entity); } @DELETE @Path("{id}") public void remove(@PathParam("id") Integer id) { customerFacade.remove(customerFacade.find(id)); } @GET @Path("{id}") @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) public Customer find(@PathParam("id") Integer id) { return customerFacade.find(id); } @GET @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) public List<Customer> findAll() { return customerFacade.findAll(); } @GET @Path("{from}/{to}") @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) public List<Customer> findRange(@PathParam("from") Integer from, @PathParam("to") Integer to) { return customerFacade.findRange(new int[]{from, to}); } @GET @Path("count") @Produces(MediaType.TEXT_PLAIN) public String countREST() { return String.valueOf(customerFacade.count()); } }