SpringBoot XML RestAPIs + MySQL – Post/Get/Put/Delete Requests Example

springboot-xml-restapi-mysql---feature-image

In the tutorial, Grokonez show you how to create SpringBoot XML RestAPIs and MySQL with Post/Get/Put/Delete requests using jaxb-api & jackson-dataformat-xml

Related posts:
How to use Spring JPA MySQL | Spring Boot
Spring Boot GraphQL MySQL CRUD APIs example

Technologies

– SpringBoot
– MySQL
– Postman Rest-Client

Practices

Project Structure ->

springboot-xml-restapi-mysql---spring-boot-project

Create SpringBoot project

– We use SpringToolSuite to create a SpringBoot project with below dependencies:

– The jackson-dataformat-xml adds Jackson XML serializer and deserializer.

Model

– We use @JacksonXmlRootElement & @JacksonXmlProperty to create Customer.java model:

  • @JacksonXmlProperty is used to set an attribute of the element in the XML output.
  • @JacksonXmlRootElement is used to set the name for the XML output root element.

– Create an Customers.java helper class:

-> We use @JacksonXmlProperty & @JacksonXmlElementWrapper annotations to set a list of Customer to be elements of Customers element in XML output.

JPA Repository

– Create JPA repository CustomerRepository.java ->

Controller RestAPIs

– We create 4 RestAPIs with Post/Get/Put/Delete XML request-mapping:

-> With MediaType.APPLICATION_XML_VALUE, Spring uses a message converter to produces XML data.

Application configuration

– Open file application.properties, add configuration:

Run & Check Results

– Run SpringBoot application & start MySQL database.

-> Make post requests:

springboot-xml-restapi-mysql---post-request

springboot-xml-restapi-mysql---save-customers

-> Get customers:

springboot-xml-restapi-mysql---get-request-by-id

springboot-xml-restapi-mysql---get-all-customers

-> Put a customer:

springboot-xml-restapi-mysql---put-a-customer

springboot-xml-restapi-mysql---put-customers

– Delete a customer:

springboot-xml-restapi-mysql---delete-request

springboot-xml-restapi-mysql---delete-customers

Sourcecode

SpringBootXMLRestAPI

By grokonez | January 19, 2019.

Last updated on November 18, 2019.



Related Posts


Got Something To Say:

Your email address will not be published. Required fields are marked *

*