Crear un nuevo proyecto https start spring io

  • Slides: 10
Download presentation

Crear un nuevo proyecto (https: //start. spring. io/) Seleccionar: Web: Build web, including RESTful,

Crear un nuevo proyecto (https: //start. spring. io/) Seleccionar: Web: Build web, including RESTful, applications using Spring MVC. Uses Apache Tomcat as the default embedded container. Dev tools: Provides fast application restarts, Live. Reload, and configurations for enhanced development experience. H 2: Provides a fast in-memory database that supports JDBC API. JPA: Persist data in SQL stores with Java Persistence API using Spring Data and Hibernate. Rest Repositories: Exposing Spring Data repositories over REST via Spring Data REST.

Abrir STS (Eclipse para Spring) 1. Import Grade/Maven Project 2. Click derecho en la

Abrir STS (Eclipse para Spring) 1. Import Grade/Maven Project 2. Click derecho en la única Clase Java (que tiene un main) -> Run as -> Spring Boot App

Implementación Model 1. Crear un paquete model 2. Crear clase Persona @Entity // @Table

Implementación Model 1. Crear un paquete model 2. Crear clase Persona @Entity // @Table // public class Persona { @Column(name = "name", nullable = false) private String name; @Id @Generated. Value(strategy = Generation. Type. IDENTITY) private Long id; //Insertar getter, setter, equals, hashcode }

Implementación Repository 1. Crear paquete “repository” 2. Crear interfaz Persona. Repository @Repository. Rest. Resource(exported

Implementación Repository 1. Crear paquete “repository” 2. Crear interfaz Persona. Repository @Repository. Rest. Resource(exported = false) public interface Persona. Repository extends Paging. And. Sorting. Repository<Persona, Long>{ Persona find. By. Name(String name); }

To create SOAP Client: https: //howtodoinjava. com/spring-boot/spring-soap-client-webservicetemplate/ Github garbage. Recycler https: //github. com/mauriarroqui/garbage-recycler

To create SOAP Client: https: //howtodoinjava. com/spring-boot/spring-soap-client-webservicetemplate/ Github garbage. Recycler https: //github. com/mauriarroqui/garbage-recycler

Implementación Service (Lógica del Negocio) 1. Crear un paquete Service 2. Crear Interfaz Persona.

Implementación Service (Lógica del Negocio) 1. Crear un paquete Service 2. Crear Interfaz Persona. Service 3. Crear clase Persona. Service. Imp public class Persona. Service. Imp implements Persona. Service { @Autowired Persona. Repository pr; @Override public Persona register(Persona p) { return pr. save(p); } public interface Persona. Service { Persona register(Persona p); Persona find. By. Name(String name); } @Override public Persona find. By. Name(String name) { return pr. find. By. Name(name); } }

@Rest. Controller public class Persona. Controller { Implementación Controller @Autowired Persona. Service ps; @Post.

@Rest. Controller public class Persona. Controller { Implementación Controller @Autowired Persona. Service ps; @Post. Mapping(path = "/api/personas") public Response. Entity<Persona> register. Persona(@Request. Body 1. Crear un paquete “controller” 2. Crear la Persona. Controller Persona p){ Persona new. P = ps. register(p); URI location = Servlet. Uri. Components. Builder. from. Current. Request(). path("/{id}"). build. And. Expand(new. P. get. Id()). to. Uri(); return Response. Entity. created(location). body(new. P); } @Get. Mapping(path = "/api/personas") public Response. Entity<List<Persona>> get. Personas( ){ List<Persona> list = ps. get. All. Personas(); return Response. Entity. ok(list); } @Get. Mapping(path = "/api/personas/{name}/") public Response. Entity<Persona> get. Persona(@Path. Variable(value = "name") String name){ Persona p = ps. find. By. Name(name); return Response. Entity. ok(p); }

Testear ● Advance. RESTClient ● Cliente Utilizando Web. Resourse Jersey ○ http: //www. mkyong.

Testear ● Advance. RESTClient ● Cliente Utilizando Web. Resourse Jersey ○ http: //www. mkyong. com/webservices/jax-rs/restful-java-client-with-jersey-client/ HAY MUCHAS OTROS!!!! ● Base de datos en memoria ○ http: //localhost: 8080/h 2 -console/ ○ URL jdbc: h 2: mem: testdb ○ user name: sa ○ password: ○ (sin password)

Github Recicler https: //github. com/mauriarroqui/garbage-recycler Cliente SOAP https: //howtodoinjava. com/spring-boot/spring-soap-client-webservicetemplate/

Github Recicler https: //github. com/mauriarroqui/garbage-recycler Cliente SOAP https: //howtodoinjava. com/spring-boot/spring-soap-client-webservicetemplate/