Spring Data JPA with MySql

Spring Data JPA is a powerful tool that simplifies database access in Spring Boot applications. In this tutorial, we’ll create a Spring Boot application that uses Spring Data JPA to perform CRUD (Create, Read, Update, Delete) operations on a MySQL database.

As part of this example we're going to use following annotations to perform the CRUD operations.

  1. 1. PostMapping.
  2. 2. GetMapping.
  3. 3. DeleteMapping.
  4. 4. PutMapping.

As part of this below endpoints will be used to perform the CRUD operations.

  1. HTTP POST /api/v1/customer/create – create a customer.
  2. HTTP GET /api/v1/customer/getAll – returns all the customers in the system.
  3. HTTP GET /api/v1/customer/getById/{customerId} – returns a customer by specified id.
  4. HTTP DELETE /api/v1/customer/deleteById/{customerId} – delete a customer by specified id.
  5. HTTP PUT /api/v1/customer/update – update a customer by specified id.

Will perform the CRUS operation without using without database storage.

@PostMapping annotation is a simplified compact version of @RequestMapping(method-RequestMathod.POST)
@GetMapping annotation is a simplified compact version of @RequestMapping(method-RequestMathod.GET)
@DeleteMapping annotation is a simplified compact version of @RequestMapping(method-RequestMathod.DELETE)
@PutMapping annotation is a simplified compact version of @RequestMapping(method-RequestMathod.PUT)

SpringBoot provides a web tool to generate a initial bootstrap applicaiton which is Spring Initializer. If you want to learn the more about Spring initializer and how to use it to create the application visit following tutorial Create Springboot Application.

Project Strucure

pom.xml

While generating the SpringBoot project, will make sure that to add following Maven dependencies.


                        <?xml version="1.0" encoding="UTF-8"?>
                        <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                            xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
                            <modelVersion>4.0.0</modelVersion>
                            <parent>
                                <groupId>org.springframework.boot</groupId>
                                <artifactId>spring-boot-starter-parent</artifactId>
                                <version>3.3.0</version>
                                <relativePath/> <!-- lookup parent from repository -->
                            </parent>
                            <groupId>com.sb.sdjpa.crud</groupId>
                            <artifactId>customer-registration</artifactId>
                            <version>0.0.1-SNAPSHOT</version>
                            <name>customer-registration</name>
                            <description>Demo project for Spring Boot</description>
                            <url/>
                            <licenses>
                                <license/>
                            </licenses>
                            <developers>
                                <developer/>
                            </developers>
                            <scm>
                                <connection/>
                                <developerConnection/>
                                <tag/>
                                <url/>
                            </scm>
                            <properties>
                                <java.version>17</java.version>
                            </properties>
                            <dependencies>
                                <dependency>
                                    <groupId>org.springframework.boot</groupId>
                                    <artifactId>spring-boot-starter-data-jpa</artifactId>
                                </dependency>
                                <dependency>
                                    <groupId>org.springframework.boot</groupId>
                                    <artifactId>spring-boot-starter-web</artifactId>
                                </dependency>
                        
                                <dependency>
                                    <groupId>mysql</groupId>
                                    <artifactId>mysql-connector-java</artifactId>
                                    <version>8.0.28</version>
                                </dependency>
                                <dependency>
                                    <groupId>org.projectlombok</groupId>
                                    <artifactId>lombok</artifactId>
                                    <optional>true</optional>
                                </dependency>
                                <dependency>
                                    <groupId>org.springframework.boot</groupId>
                                    <artifactId>spring-boot-starter-test</artifactId>
                                    <scope>test</scope>
                                </dependency>
                            </dependencies>
                        
                            <build>
                                <plugins>
                                    <plugin>
                                        <groupId>org.springframework.boot</groupId>
                                        <artifactId>spring-boot-maven-plugin</artifactId>
                                        <configuration>
                                            <excludes>
                                                <exclude>
                                                    <groupId>org.projectlombok</groupId>
                                                    <artifactId>lombok</artifactId>
                                                </exclude>
                                            </excludes>
                                        </configuration>
                                    </plugin>
                                </plugins>
                            </build>
                        
                        </project>
                        
                    

CustomerRegistrationApplication.java

                    package com.sb.sdjpa.crud;

                    import org.springframework.boot.SpringApplication;
                    import org.springframework.boot.autoconfigure.SpringBootApplication;

                    @SpringBootApplication
                    public class CustomerRegistrationApplication {

                        public static void main(String[] args) {
                            SpringApplication.run(CustomerRegistrationApplication.class, args);
                        }
                    }
                  

Request.java

                    package com.sb.sdjpa.crud.request;

                    import lombok.AllArgsConstructor;
                    import lombok.Getter;
                    import lombok.NoArgsConstructor;
                    import lombok.Setter;
                    import lombok.EqualsAndHashCode;
                    import lombok.Builder;

                    @Getter
                    @Setter
                    @NoArgsConstructor
                    @AllArgsConstructor
                    @EqualsAndHashCode
                    @Builder(toBuilder = true)
                    public class CustomerRequest {
                        private String customerName;
                        private int customerAge;
                        private String customerMobileNumber;
                        private String customerEmailAddress;
                        private String customerAddress;
                    }
                       
                  

@Getter: This annotation will help to enable the all getter methods.
@Setter: This annotation will help to enable the all setter methods.
@NoArgsConstructor: This annotation will help to enable the no argument NoArgsConstructor.
@AllArgsConstructor: This annotation will help to create the AllArgsConstructor.
@EqualsAndHashCode: This annotation will overrides the equals and hashcode method.
@Builder: This annotation will eliminates the need to write boilerplate code for constructors with many parameters. It generates the builder class and its methods automatically. this will allow us to set only the fields that is needed, making it easy to work with classes that have many optional attributes.

CustomerController.java

                    package com.sb.sdjpa.crud.controller;

                    import com.sb.sdjpa.crud.request.CustomerRequest;
                    import com.sb.sdjpa.crud.response.APIResponse;
                    import com.sb.sdjpa.crud.service.CustomerService;
                    import lombok.RequiredArgsConstructor;
                    import org.springframework.http.ResponseEntity;
                    import org.springframework.web.bind.annotation.*;

                    @RestController
                    @RequestMapping("/api/v1/customer")
                    @RequiredArgsConstructor
                    public class CustomerController {

                        private final CustomerService customerService;

                        /**
                        * create a customer, in case of post mapping this method will get invoked.
                        *
                        * @param request customer request
                        * @return response entity object
                        */
                        @PostMapping("/create")
                        public ResponseEntity<APIResponse> createCustomer(@RequestBody CustomerRequest request) {
                            return customerService.createCustomer(request);
                        }

                        /**
                        * get all the customer from the database, in case of get mapping with /getAll endpoint this method will get invoked.
                        *
                        * @return response entity object
                        */
                        @GetMapping("/getAll")
                        public ResponseEntity<APIResponse> getAllCustomer() {
                            return customerService.getAllCustomers();
                        }

                        /**
                        * get a specific customer from the database, in case of get mapping with /getById endpoint this method will get invoked.
                        *
                        * @param customerId customer id
                        * @return response entity object
                        */
                        @GetMapping("/getById/{customerId}")
                        public ResponseEntity<APIResponse> getByCustomerId(@PathVariable long customerId) {
                            return customerService.getByCustomerId(customerId);
                        }

                        /**
                        * delete a specific customer from the database, in case of delete mapping this method will get invoked.
                        *
                        * @param customerId customer id
                        * @return response entity object
                        */
                        @DeleteMapping("/deleteById/{customerId}")
                        public ResponseEntity<APIResponse> deleteByCustomerId(@PathVariable long customerId) {
                            return customerService.deleteByCustomerId(customerId);
                        }

                        /**
                        * update a specific customer, in case of put mapping this method will get invoked.
                        *
                        * @param customerId customer id
                        * @param request customer request object
                        * @return response entity object
                        */
                        @PutMapping("/update/{customerId}")
                        public ResponseEntity<APIResponse> updateCustomer(@PathVariable long customerId, @RequestBody CustomerRequest request) {
                            return customerService.updateCustomerDetails(customerId, request);
                        }
                    }

                  

@RestController: This annotation is used to indicate that this class is a REST controller, which means it handles incoming HTTP requests and returns the corresponsing responses.
@RequestMapping: This annotation is used to specifies the base URL path for all the request mappings defined whith this controller.
@RequiredArgsConstructor: This annotation is used to generate the contructor with required arguments to enable the construtor injection in defined controller.
@PostMapping: This annotation is used to maps the specified method to the HTTP POST method for the base URL path.
@GetMapping: This annotation is used to handle the HTTP GET requests matched with the given URI expression.
@DeleteMapping: This annotation is used to handle the HTTP DELETE requests matched with the given URI expression.
@PutMapping: This annotation is used to maps the specified method to the HTTP PUT method for the base URL path.
@RequestBody: This annotation is used to bind the request body to the CustomerRequest object, which represents the CustomerRequest items to be added.
ResponseEntity: This object is used to send the HTTP response back to the client.

APIResponse.java

This we're going to use it as a common response object, will render all our responses and send back to the client.


                    package com.sb.sdjpa.crud.response;

                    import lombok.AllArgsConstructor;
                    import lombok.Getter;
                    import lombok.NoArgsConstructor;
                    import lombok.Setter;
                    import lombok.EqualsAndHashCode;
                    import lombok.Builder;

                    @Getter
                    @Setter
                    @NoArgsConstructor
                    @AllArgsConstructor
                    @EqualsAndHashCode
                    @Builder(toBuilder = true)
                    public class APIResponse {
                        private int errorCode;
                        private String errorMessage;
                        private Object data;
                    }
                    
                  

CustomerResponse.java

The customerResponse class is used like a DTO to carry the result from model to controller, so that we can map this with response entity to return it to the client.


                    package com.sb.sdjpa.crud.response;

                    import com.sb.sdjpa.crud.enums.CustomerStatus;
                    import lombok.AllArgsConstructor;
                    import lombok.Getter;
                    import lombok.NoArgsConstructor;
                    import lombok.Setter;
                    import lombok.EqualsAndHashCode;
                    import lombok.Builder;
                    import lombok.ToString;
                    import java.time.LocalDateTime;

                    @Getter
                    @Setter
                    @NoArgsConstructor
                    @AllArgsConstructor
                    @ToString
                    @EqualsAndHashCode
                    @Builder(toBuilder = true)
                    public class CustomerResponse {
                        private Long customerId;
                        private String customerName;
                        private int customerAge;
                        private String customerMobileNumber;
                        private String customerEmailAddress;
                        private String customerAddress;
                        private CustomerStatus status;
                        private boolean verified;
                        private LocalDateTime createdDate;
                        private LocalDateTime updatedDate;
                    }
                    
                  

CustomerService.java

                    package com.sb.sdjpa.crud.service;

                    import com.sb.sdjpa.crud.request.CustomerRequest;
                    import com.sb.sdjpa.crud.response.APIResponse;
                    import org.springframework.http.ResponseEntity;

                    public interface CustomerService {
                        ResponseEntity<APIResponse> createCustomer(CustomerRequest request);
                        ResponseEntity<APIResponse> getAllCustomers();
                        ResponseEntity<APIResponse> getByCustomerId(long customerId);
                        ResponseEntity<APIResponse> deleteByCustomerId(long customerId);
                        ResponseEntity<APIResponse> updateCustomerDetails(long customerId, CustomerRequest request);
                    }
                  

CustomerServiceImpl.java

                    package com.sb.sdjpa.crud.service.impl;

                    import com.sb.sdjpa.crud.model.CustomerModel;
                    import com.sb.sdjpa.crud.repository.CustomerRepository;
                    import com.sb.sdjpa.crud.request.CustomerRequest;
                    import com.sb.sdjpa.crud.response.APIResponse;
                    import com.sb.sdjpa.crud.response.CustomerResponse;
                    import com.sb.sdjpa.crud.service.CustomerService;
                    import lombok.RequiredArgsConstructor;
                    import org.springframework.http.ResponseEntity;
                    import org.springframework.stereotype.Service;
                    import java.util.List;
                    import java.util.Optional;

                    import static com.sb.sdjpa.crud.constants.AppConstants.*;
                    import static com.sb.sdjpa.crud.mapper.CustomerMapper.modelToResponseMapper;
                    import static com.sb.sdjpa.crud.mapper.CustomerMapper.requestToModel;

                    /**
                    * This class holds all the business logic, and it will be used as a interface between controller and DAO layer.
                    */
                    @Service
                    @RequiredArgsConstructor
                    public class CustomerServiceImpl implements CustomerService {

                        private final CustomerRepository customerRepository;

                        /**
                        * This method is used to store the customer details into the database.
                        *
                        * @param request customer request
                        * @return responseEntity object
                        */
                        @Override
                        public ResponseEntity<APIResponse> createCustomer(CustomerRequest request) {

                            CustomerModel customerModel = customerRepository.save(requestToModel(request));

                            return ResponseEntity.ok(
                                    APIResponse.builder()
                                            .errorCode(SUCCESS_CODE)
                                            .errorMessage(SUCCESSFULLY_STORED)
                                            .data(modelToResponseMapper(customerModel))
                                            .build()
                            );
                        }

                        /**
                        * This method is used to fetch all the customers from the database.
                        *
                        * @return responseEntity object
                        */
                        @Override
                        public ResponseEntity<APIResponse> getAllCustomers() {
                            List<CustomerModel> customerDetails = customerRepository.findAll();
                            List<CustomerResponse> customers = customerDetails.stream()
                                    .map(customerModel -> modelToResponseMapper(customerModel))
                                    .toList();

                            return ResponseEntity.ok(
                                    APIResponse.builder()
                                            .errorCode(SUCCESS_CODE)
                                            .errorMessage(SUCCESSFULLY_RETRIEVED)
                                            .data(customers)
                                            .build()
                            );
                        }

                        /**
                        * Fetch customer based on the specific id.
                        *
                        * @param customerId customer id
                        * @return responseEntity object
                        */
                        @Override
                        public ResponseEntity<APIResponse> getByCustomerId(long customerId) {
                            Optional<CustomerModel> modelOptional = customerRepository.findById(customerId);
                            if (!modelOptional.isPresent()) {
                                return ResponseEntity.ok(
                                        APIResponse.builder()
                                                .errorCode(CUSTOMER_NOT_EXISTS_CODE)
                                                .errorMessage(CUSTOMER_NOT_EXISTS)
                                                .data(List.of())
                                                .build()
                                );
                            }

                            CustomerModel model = modelOptional.get();
                            CustomerResponse response = modelToResponseMapper(model);
                            return ResponseEntity.ok(
                                    APIResponse.builder()
                                            .errorCode(SUCCESS_CODE)
                                            .errorMessage(SUCCESSFULLY_RETRIEVED)
                                            .data(response)
                                            .build()
                            );
                        }

                        /**
                        * This method is used to delete the customer from the database.
                        *
                        * @param customerId customer id
                        * @return responseEntity object
                        */
                        @Override
                        public ResponseEntity<APIResponse> deleteByCustomerId(long customerId) {

                            Optional<CustomerModel> modelOptional = customerRepository.findById(customerId);

                            if (!modelOptional.isPresent()) {
                                return ResponseEntity.ok(
                                        APIResponse.builder()
                                                .errorCode(CUSTOMER_NOT_EXISTS_CODE)
                                                .errorMessage(CUSTOMER_NOT_EXISTS)
                                                .data(List.of())
                                                .build()
                                );
                            }
                            customerRepository.deleteById(customerId);
                            return ResponseEntity.ok(
                                    APIResponse.builder()
                                            .errorCode(SUCCESS_CODE)
                                            .errorMessage(SUCCESSFULLY_DELETED)
                                            .data(List.of())
                                            .build()
                            );
                        }

                        /**
                        * This method is used to update the customer details into the database.
                        *
                        * @param customerId customer id
                        * @param request customer request object
                        * @return responseEntity object
                        */
                        @Override
                        public ResponseEntity<APIResponse> updateCustomerDetails(long customerId, CustomerRequest request) {

                            Optional<CustomerModel> modelOptional = customerRepository.findById(customerId);
                            if (modelOptional.isPresent()) {
                                CustomerModel model = modelOptional.get();
                                model.setCustomerName(request.getCustomerName());
                                model.setCustomerAge(request.getCustomerAge());
                                model.setCustomerMobileNumber(request.getCustomerMobileNumber());
                                model.setCustomerEmailAddress(request.getCustomerEmailAddress());
                                model.setCustomerAddress(request.getCustomerAddress());
                                model = customerRepository.save(model);

                                return ResponseEntity.ok(
                                        APIResponse.builder()
                                                .errorCode(SUCCESS_CODE)
                                                .errorMessage(SUCCESSFULLY_UPDATED)
                                                .data(modelToResponseMapper(model))
                                                .build()
                                );
                            } else {
                                return ResponseEntity.ok(
                                        APIResponse.builder()
                                                .errorCode(CUSTOMER_NOT_EXISTS_CODE)
                                                .errorMessage(CUSTOMER_NOT_EXISTS)
                                                .data(List.of())
                                                .build()
                                );
                            }
                        }
                    }

                  

AppUtils.java

                    package com.sb.sdjpa.crud.utils;

                    import java.security.SecureRandom;
                    import java.util.stream.Collectors;

                    import static com.sb.sdjpa.crud.constants.AppConstants.*;

                    /**
                    * AppUtils, all application level utility methods will be placed here.
                    */
                    public class AppUtils {

                        /**
                        * This method is used to generate the random alphanumaric string for the password.
                        *
                        * @return String autogenerated random value
                        */
                        public static String generatePassword() {
                            SecureRandom random = new SecureRandom();
                            return random.ints(PASS_LENGTH, 0, PASS_CHARACTERS.length())
                                    .mapToObj(PASS_CHARACTERS::charAt)
                                    .map(Object::toString)
                                    .collect(Collectors.joining());

                        }

                        /**
                        * This method is used to generate the random numbers for an OTP.
                        *
                        * @return string 6 digits otp
                        */
                        public static String generateOtp() {
                            SecureRandom random = new SecureRandom();
                            return random.ints(OTP_LENGTH, 0, OTP_CHARACTERS.length())
                                    .mapToObj(OTP_CHARACTERS::charAt)
                                    .map(Object::toString)
                                    .collect(Collectors.joining());
                        }
                    }

                  

CustomerRepository.java

                    package com.sb.sdjpa.crud.repository;

                    import com.sb.sdjpa.crud.model.CustomerModel;
                    import org.springframework.data.jpa.repository.JpaRepository;

                    public interface CustomerRepository extends JpaRepository {
                    }

                  

CustomerModel.java

                    package com.sb.sdjpa.crud.model;

                    import com.sb.sdjpa.crud.enums.CustomerStatus;

                    import jakarta.persistence.GenerationType;
                    import jakarta.persistence.TemporalType;
                    import jakarta.persistence.EnumType;

                    import jakarta.persistence.Entity;
                    import jakarta.persistence.Table;
                    import jakarta.persistence.Id;
                    import jakarta.persistence.GeneratedValue;
                    import jakarta.persistence.Column;
                    import jakarta.persistence.Enumerated;
                    import jakarta.persistence.Temporal;
                    import lombok.AllArgsConstructor;
                    import lombok.Getter;
                    import lombok.NoArgsConstructor;
                    import lombok.Setter;
                    import lombok.EqualsAndHashCode;
                    import lombok.Builder;
                    import lombok.ToString;
                    import org.hibernate.annotations.CreationTimestamp;
                    import org.hibernate.annotations.UpdateTimestamp;

                    import java.io.Serializable;
                    import java.time.LocalDateTime;

                    @Getter
                    @Setter
                    @NoArgsConstructor
                    @AllArgsConstructor
                    @ToString
                    @EqualsAndHashCode
                    @Builder(toBuilder = true)
                    @Entity
                    @Table(name = "customer_details")
                    public class CustomerModel implements Serializable {

                        @Id
                        @GeneratedValue(strategy = GenerationType.SEQUENCE)
                        @Column(name = "id")
                        private Long customerId;

                        @Column(name = "customer_name")
                        private String customerName;

                        @Column(name = "password")
                        private String customerPassword;

                        @Column(name = "customer_age")
                        private int customerAge;

                        @Column(name = "customer_mobile_number")
                        private String customerMobileNumber;

                        @Column(name = "customer_email_address")
                        private String customerEmailAddress;

                        @Column(name = "customer_address")
                        private String customerAddress;

                        @Column(name = "status")
                        private CustomerStatus status;

                        @Column(name = "otp")
                        private String customerOtp;

                        @Column(name = "verified")
                        private boolean verified;

                        @Column(name = "created_by")
                        @Temporal(TemporalType.TIMESTAMP)
                        @CreationTimestamp
                        private LocalDateTime createdDate;

                        @Column(name = "updated_by")
                        @Temporal(TemporalType.TIMESTAMP)
                        @UpdateTimestamp
                        private LocalDateTime updatedDate;
                    }

                  

CustomerMapper.java
>

                        package com.sb.sdjpa.crud.mapper;

                        import com.sb.sdjpa.crud.enums.CustomerStatus;
                        import com.sb.sdjpa.crud.model.CustomerModel;
                        import com.sb.sdjpa.crud.request.CustomerRequest;
                        import com.sb.sdjpa.crud.response.CustomerResponse;

                        import java.time.LocalDate;

                        import static com.sb.sdjpa.crud.utils.AppUtils.generateOtp;
                        import static com.sb.sdjpa.crud.utils.AppUtils.generatePassword;

                        public class CustomerMapper {
                            public static CustomerResponse modelToResponseMapper(CustomerModel customerModel) {
                                return CustomerResponse.builder()
                                        .customerId(customerModel.getCustomerId())
                                        .customerName(customerModel.getCustomerName())
                                        .customerAge(customerModel.getCustomerAge())
                                        .customerMobileNumber(customerModel.getCustomerMobileNumber())
                                        .customerEmailAddress(customerModel.getCustomerEmailAddress())
                                        .customerAddress(customerModel.getCustomerAddress())
                                        .createdDate(customerModel.getCreatedDate())
                                        .status(customerModel.getStatus())
                                        .verified(customerModel.isVerified())
                                        .createdDate(customerModel.getCreatedDate())
                                        .updatedDate(customerModel.getUpdatedDate())
                                        .build();
                            }

                            public static CustomerModel requestToModel(CustomerRequest request) {
                                return CustomerModel.builder()
                                        .customerName(request.getCustomerName())
                                        .customerPassword(generatePassword())
                                        .customerAge(request.getCustomerAge())
                                        .customerMobileNumber(request.getCustomerMobileNumber())
                                        .customerEmailAddress(request.getCustomerEmailAddress())
                                        .customerAddress(request.getCustomerAddress())
                                        .status(CustomerStatus.INACTIVE)
                                        .customerOtp(generateOtp())
                                        .verified(Boolean.FALSE)
                                        .build();
                            }
                        }

                    

CustomerStatus.java
>

                        package com.sb.sdjpa.crud.enums;

                        import com.fasterxml.jackson.annotation.JsonCreator;
                        import com.fasterxml.jackson.annotation.JsonValue;
                        
                        /**
                         * Customer status enum with constant values.
                         */
                        public enum CustomerStatus {
                            ACTIVE,
                            INACTIVE;
                        }
                    

AppConstants.java
>

                        package com.sb.sdjpa.crud.constants;

                        public class AppConstants {

                            // Utility Constants
                            public static final String PASS_CHARACTERS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
                            public static final int PASS_LENGTH = 12;
                            public static final String OTP_CHARACTERS = "0123456789";
                            public static final int OTP_LENGTH = 6;

                            // Service layer constants
                            public static final Integer SUCCESS_CODE = 111;
                            public static final String SUCCESSFULLY_STORED = "Data Successfully Stored";
                            public static final String SUCCESSFULLY_RETRIEVED = "Data Successfully Retrieved";
                            public static final String SUCCESSFULLY_DELETED = "Data Successfully Deleted";
                            public static final String SUCCESSFULLY_UPDATED = "Data Successfully Updated";
                            public static final Integer CUSTOMER_NOT_EXISTS_CODE = 900;
                            public static final String CUSTOMER_NOT_EXISTS = "Customer is not registered";
                        }

                    

application.properties

                    spring:
                        application:
                            name: customer-registration
                        datasource:
                            url: jdbc:mysql://localhost:3306/customerdb
                            username: root
                            password: PASSWORD
                            driver-class-name: com.mysql.cj.jdbc.Driver
                        jpa:
                            properties:
                            hibernate:
                                dialect: org.hibernate.dialect.MySQL8Dialect
                            hibernate:
                            ddl-auto: update
                            show-sql: true

                        server:
                        port: 8087

                  

Postman calls

Execute below endpoint through postman then verify the MySQL Entires through mysql workbench

  1. Create: POST: http://localhost:8087/api/v1/customer/create
  2. GetAll Customers: GET: http://localhost:8087/api/v1/customer/getAll
  3. GetById: GET: http://localhost:8087/api/v1/customer/getAll
  4. DeleteById: DELETE: http://localhost:8087/api/v1/customer/deleteById/152
  5. Update: Put: http://localhost:8087/api/v1/customer/update/153

Full source code is available in follwong GitHub repository: SpringBoot Mysql Customer Registration example