Posts

Showing posts from February, 2025

Basic application to insert data into database

  Spring Boot CRUD Application Overview This is a simple Spring Boot CRUD application that demonstrates how to create, read, update, and delete data in a MySQL database. Database Details The application uses the following MySQL database details: Database Name:  registrationDb Table Name:  registration Table Structure The  registration  table has the following structure: CREATE TABLE registration.sql CREATE TABLE registration ( id INT AUTO_INCREMENT, name VARCHAR(255), email VARCHAR(255), PRIMARY KEY ( id ) ); How it Works The application works as follows: The user sends an HTTP request to the  UserController  class. The  UserController  class calls the  RegistrationService  class to perform the business logic. The  RegistrationService  class calls the  RegistrationDao  class to perform the data access logic. The  RegistrationDao  class interacts with the MySQL database...

Basic Spring Boot Controller Class Annotations

Basic Spring Boot Controller Class Annotations Overview of Dispatcher Servlet When a user hits an API (e.g., a GET call to fetch a user), the Dispatcher Servlet uses Handler Mapping to identify the appropriate controller to handle the request. Key Annotations for Handler Mapping @Controller Indicates that the class is responsible for handling incoming HTTP requests. @RestController Similar to  @Controller , but it combines  @Controller  and  @ResponseBody . Difference Between @Controller and @RestController @Controller  requires  @ResponseBody  on each method, while  @RestController  automatically applies it to all methods. Request Mapping To map APIs to controller methods, we use the  @RequestMapping  annotation. Example: @RequestMapping("/api/v1") public class SampleController { @GetMapping("/fetchUser ") public String getUser Details() { // Logic to fetch user details } } Simplified Mapping Annotations @GetMap...