<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Akash Vadakkeveetil</title>
    <description>The latest articles on DEV Community by Akash Vadakkeveetil (@akash_vadakkeveetil).</description>
    <link>https://dev.to/akash_vadakkeveetil</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3553169%2F05589241-d674-4657-834c-cccaca7f1e37.jpg</url>
      <title>DEV Community: Akash Vadakkeveetil</title>
      <link>https://dev.to/akash_vadakkeveetil</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/akash_vadakkeveetil"/>
    <language>en</language>
    <item>
      <title>Basic CRUD using Java Spring Boot</title>
      <dc:creator>Akash Vadakkeveetil</dc:creator>
      <pubDate>Sat, 13 Dec 2025 12:07:17 +0000</pubDate>
      <link>https://dev.to/akash_vadakkeveetil/basic-crud-using-java-spring-boot-2l07</link>
      <guid>https://dev.to/akash_vadakkeveetil/basic-crud-using-java-spring-boot-2l07</guid>
      <description>&lt;h2&gt;
  
  
  What is in this blog?
&lt;/h2&gt;

&lt;p&gt;So we are going to look into Java Spring Boot for creating a basic backend system, which interacts with a database and does basic CRUD (Create, Read, Update, Delete) operations.&lt;/p&gt;

&lt;p&gt;The main idea is to cover the most basic working of this backend framework, like the simplest form of function that a backend framework can perform.&lt;/p&gt;

&lt;p&gt;Ok, so this post explores how to implement a basic, robust CRUD API using Spring Boot, the industry standard for modern Java backend development, backed by a MySQL database.&lt;/p&gt;

&lt;h3&gt;
  
  
  What is Spring Boot
&lt;/h3&gt;

&lt;p&gt;Spring Boot is a Java framework that helps you build web and backend applications easily. It takes care of most of the setup and configuration for you, so you can focus on writing your code instead of managing complex settings.&lt;/p&gt;

&lt;p&gt;Let's get started.&lt;/p&gt;

&lt;p&gt;First, install Java (JDK) in your system.&lt;br&gt;
Then, we have to create a Java Spring project. To do that, go to the &lt;a href="https://start.spring.io/" rel="noopener noreferrer"&gt;Spring initializer website&lt;/a&gt; and create a new project. Give the application a name, select Java versions, and add dependencies. Dependencies are additional libraries or packages that help a Java application access and use different functionalities.&lt;br&gt;
Hit generate, and the package will be in your system.&lt;/p&gt;

&lt;p&gt;Open the generated folder in any &lt;a href="https://www.geeksforgeeks.org/blogs/what-is-ide/" rel="noopener noreferrer"&gt;IDE&lt;/a&gt;. The most preferred one for Java-related projects is IntelliJ IDEA. You can go and download the community version from &lt;a href="https://www.jetbrains.com/idea/" rel="noopener noreferrer"&gt;the official site&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;First, you have to know what all the stuff is inside the generated folder. In short, you have to know the Spring architecture.&lt;/p&gt;

&lt;p&gt;A typical Spring Boot application that handles CRUD operations follows a layered architecture to maintain separation of concerns:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Entity/Model&lt;/strong&gt;: The Java class representing the data structure in the database (e.g., User or Product).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Repository Layer&lt;/strong&gt;: The interface that interacts directly with the database. Spring Data JPA makes this simple by automatically providing basic CRUD methods.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Service Layer&lt;/strong&gt;: Contains the business logic. It uses the Repository to perform database operations.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Controller Layer&lt;/strong&gt;: The entry point for the application. It receives HTTP requests, calls the Service layer, and returns an HTTP response.&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Operation&lt;/th&gt;
&lt;th&gt;Function&lt;/th&gt;
&lt;th&gt;HTTP Method&lt;/th&gt;
&lt;th&gt;Spring Annotation&lt;/th&gt;
&lt;th&gt;Repository Method&lt;/th&gt;
&lt;th&gt;Purpose&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Create&lt;/td&gt;
&lt;td&gt;Insert Data&lt;/td&gt;
&lt;td&gt;POST&lt;/td&gt;
&lt;td&gt;@PostMapping&lt;/td&gt;
&lt;td&gt;save(entity)&lt;/td&gt;
&lt;td&gt;Add a new record to the database.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Read&lt;/td&gt;
&lt;td&gt;Retrieve Data&lt;/td&gt;
&lt;td&gt;GET&lt;/td&gt;
&lt;td&gt;@GetMapping&lt;/td&gt;
&lt;td&gt;findAll(), findById(id)&lt;/td&gt;
&lt;td&gt;Fetch one or all records.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Update&lt;/td&gt;
&lt;td&gt;Modify Data&lt;/td&gt;
&lt;td&gt;PUT&lt;/td&gt;
&lt;td&gt;@PutMapping&lt;/td&gt;
&lt;td&gt;save(entity)&lt;/td&gt;
&lt;td&gt;Change an existing record's data.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Delete&lt;/td&gt;
&lt;td&gt;Remove Data&lt;/td&gt;
&lt;td&gt;DELETE&lt;/td&gt;
&lt;td&gt;@DeleteMapping&lt;/td&gt;
&lt;td&gt;deleteById(id)&lt;/td&gt;
&lt;td&gt;Permanently remove a record.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;
&lt;h2&gt;
  
  
  1. Create (C)
&lt;/h2&gt;

&lt;p&gt;Goal: To save a new entity (like a new user) to the MySQL database.&lt;/p&gt;

&lt;p&gt;Controller: An endpoint annotated with @PostMapping receives the new entity data, typically as a JSON body in the request.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nd"&gt;@PostMapping&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"/addStudent"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="nf"&gt;postDetails&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nd"&gt;@RequestBody&lt;/span&gt; &lt;span class="nc"&gt;StudentEntity&lt;/span&gt; &lt;span class="n"&gt;studentEntity&lt;/span&gt;&lt;span class="o"&gt;){&lt;/span&gt;

        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Student entity received: "&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;studentEntity&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="c1"&gt;//we are gonna access the save details function via the service class&lt;/span&gt;
        &lt;span class="n"&gt;studentService&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;saveDetails&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;studentEntity&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s"&gt;"ADDED TO TABLE SUCCESSFULLY"&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Service: The Controller passes the data to a service method, which then calls the Repository's built-in save(entity) method.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;    &lt;span class="c1"&gt;//first function for adding to a database&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;StudentEntity&lt;/span&gt; &lt;span class="nf"&gt;saveDetails&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;StudentEntity&lt;/span&gt; &lt;span class="n"&gt;studentEntity&lt;/span&gt;&lt;span class="o"&gt;){&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;studentRepository&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;save&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;studentEntity&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;&lt;span class="c1"&gt;//to save and access we have to use repo&lt;/span&gt;
        &lt;span class="c1"&gt;//save saves our data in our table&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Result: A new row is inserted into the corresponding MySQL table.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Read (R)
&lt;/h2&gt;

&lt;p&gt;Goal: To fetch data from the database. This usually involves two main scenarios:&lt;/p&gt;

&lt;p&gt;Read All: An endpoint annotated with @GetMapping (e.g., /api/users). The Service calls the Repository's findAll() method, returning a list of all entities.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;    &lt;span class="nd"&gt;@GetMapping&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"/getStudent"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;List&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;StudentEntity&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;getDetails&lt;/span&gt;&lt;span class="o"&gt;(){&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;studentService&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getAllDetails&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Read by ID: An endpoint like &lt;code&gt;/api/users/{id}&lt;/code&gt;. The Controller uses the path variable (id) to call the Service, which in turn calls the Repository's findById(id) method. This method returns an Optional, requiring a check to handle cases where the ID does not exist.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;    &lt;span class="nd"&gt;@GetMapping&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"/getStudent/{id}"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;StudentEntity&lt;/span&gt; &lt;span class="nf"&gt;getDetailsById&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nd"&gt;@PathVariable&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="o"&gt;){&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;studentService&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getAllDetailsById&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The service code for both&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;    &lt;span class="c1"&gt;//get all details&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;List&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;StudentEntity&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;getAllDetails&lt;/span&gt;&lt;span class="o"&gt;(){&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;studentRepository&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;findAll&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="c1"&gt;//fetch data by id&lt;/span&gt;
    &lt;span class="c1"&gt;//we are using here entity itself cause we are returning a row itself , cause it is also an object of student hence we are returning so&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;StudentEntity&lt;/span&gt; &lt;span class="nf"&gt;getAllDetailsById&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="o"&gt;){&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;studentRepository&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;findById&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="o"&gt;).&lt;/span&gt;&lt;span class="na"&gt;orElse&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  3. Update (U)
&lt;/h2&gt;

&lt;p&gt;Goal: To modify an existing entity in the database.&lt;/p&gt;

&lt;p&gt;Controller: An endpoint annotated with @PutMapping (e.g., /api/users/{id}). It takes both the ID (to find the existing record) and the updated entity data.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;    &lt;span class="nd"&gt;@PostMapping&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"/updateStudent"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;StudentEntity&lt;/span&gt; &lt;span class="nf"&gt;updateDetails&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nd"&gt;@RequestBody&lt;/span&gt; &lt;span class="nc"&gt;StudentEntity&lt;/span&gt; &lt;span class="n"&gt;studentEntity&lt;/span&gt;&lt;span class="o"&gt;){&lt;/span&gt;

        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;studentService&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;updateAllDetail&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;studentEntity&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Service:&lt;/p&gt;

&lt;p&gt;First, the service calls findById(id) to retrieve the existing record.&lt;/p&gt;

&lt;p&gt;If the record exists, the new data is applied to the existing entity object.&lt;/p&gt;

&lt;p&gt;Finally, the service calls the Repository's save(updatedEntity) method again. Since the entity already has an ID, Spring Data JPA recognizes it as an update operation instead of an insert.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;StudentEntity&lt;/span&gt; &lt;span class="nf"&gt;updateAllDetail&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;StudentEntity&lt;/span&gt; &lt;span class="n"&gt;studentEntity&lt;/span&gt;&lt;span class="o"&gt;){&lt;/span&gt;
        &lt;span class="nc"&gt;StudentEntity&lt;/span&gt; &lt;span class="n"&gt;updateStudent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;studentRepository&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;findById&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;studentEntity&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getId&lt;/span&gt;&lt;span class="o"&gt;()).&lt;/span&gt;&lt;span class="na"&gt;orElse&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;&lt;span class="c1"&gt;//incase if the id is not present then we sent null&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;updateStudent&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
        &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;updateStudent&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;setMark&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;studentEntity&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getMark&lt;/span&gt;&lt;span class="o"&gt;());&lt;/span&gt;
            &lt;span class="n"&gt;updateStudent&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;setName&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;studentEntity&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getName&lt;/span&gt;&lt;span class="o"&gt;());&lt;/span&gt;
            &lt;span class="n"&gt;studentRepository&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;save&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;updateStudent&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;updateStudent&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  4. Delete (D)
&lt;/h2&gt;

&lt;p&gt;Goal: To remove a record from the database.&lt;/p&gt;

&lt;p&gt;Controller: An endpoint annotated with @DeleteMapping (e.g., /api/users/{id}).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;    &lt;span class="nd"&gt;@DeleteMapping&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"/deleteStudent/{id}"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="nf"&gt;deleteStudent&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nd"&gt;@PathVariable&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="o"&gt;){&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;studentService&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;deleteStudentById&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="o"&gt;))&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s"&gt;"Deleted Successfullly"&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s"&gt;"Cant Delete"&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Service: The Controller passes the ID to the service, which calls the Repository's deleteById(id) method.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;boolean&lt;/span&gt; &lt;span class="nf"&gt;deleteStudentById&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="o"&gt;){&lt;/span&gt;
        &lt;span class="n"&gt;studentRepository&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;deleteById&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;&lt;span class="c1"&gt;//we cant studentEnitity type , cause it will not return that after deletion&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Result: The corresponding record is permanently removed from the MySQL table.&lt;/p&gt;

&lt;p&gt;By understanding these four operations and their simple mapping to Spring Boot's layered architecture and Spring Data JPA, you have the fundamental building blocks to create any data-driven application.&lt;/p&gt;

&lt;p&gt;Wait, how do you configure a database? Let's see....&lt;/p&gt;

&lt;p&gt;There is a file called &lt;code&gt;application.properties&lt;/code&gt; in the Spring Boot application folder; you have to configure it with your database.&lt;/p&gt;

&lt;p&gt;First of all you have to create a database; you can use MySQL Workbench for it or any other platform.&lt;br&gt;
After that you can write these commands in your application.properties file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# ===============================
# = DATA SOURCE CONFIGURATION
# ===============================
spring.datasource.url=jdbc:mysql://localhost:3306/your_database_name?useSSL=false&amp;amp;serverTimezone=UTC
spring.datasource.username=your_username
spring.datasource.password=your_password
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver

# ===============================
# = JPA / HIBERNATE CONFIGURATION
# ===============================
# Hibernate dialect for MySQL
spring.jpa.database-platform=org.hibernate.dialect.MySQL8Dialect

# Automatically create or update tables based on entities
# Options: none, validate, update, create, create-drop
spring.jpa.hibernate.ddl-auto=update

# Show SQL statements in console
spring.jpa.show-sql=true

# Format SQL output for readability
spring.jpa.properties.hibernate.format_sql=true

# ===============================
# = SERVER CONFIGURATION
# ===============================
# Server port (optional)
server.port=8080

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Replace the credentials, like the password and database name, with your database name and password.&lt;/p&gt;

&lt;h3&gt;
  
  
  Folder structure:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;springboot-mvc-demo/
│
├── src/
│   ├── main/
│   │   ├── java/
│   │   │   └── com/
│   │   │       └── example/
│   │   │           └── demo/
│   │   │               ├── controller/
│   │   │               │   └── HomeController.java
│   │   │               │
│   │   │               ├── model/
│   │   │               │   └── User.java
│   │   │               │
│   │   │               ├── repository/
│   │   │               │   └── UserRepository.java
│   │   │               │
│   │   │               ├── service/
│   │   │               │   └── UserService.java
│   │   │               │
│   │   │               └── DemoApplication.java
│   │   │
│   │   ├── resources/
│   │   │   ├── static/               # static assets (CSS, JS, images)
│   │   │   ├── templates/            # Thymeleaf (or JSP) views
│   │   │   │   └── index.html
│   │   │   ├── application.properties
│   │   │   └── application.yml       # (alternative config)
│   │   │
│   │   └── webapp/                   # optional if using JSP views
│   │       └── WEB-INF/
│   │           └── views/
│   │               └── home.jsp
│   │
│   └── test/
│       └── java/
│           └── com/
│               └── example/
│                   └── demo/
│                       └── DemoApplicationTests.java
│
├── pom.xml                          # if using Maven
└── build.gradle                     # if using Gradle

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Ok, so now you can just get started. This is the basic step, and now you just have to build on top of it. &lt;br&gt;
Good luck.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;See the code at &lt;a href="https://github.com/Akash-vadakkeveetil/Basic-CRUD-SpringBoot" rel="noopener noreferrer"&gt;Github&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you have any suggestions for improvement, please feel free to leave a comment or reach out to me via inbox :)&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>webdev</category>
    </item>
  </channel>
</rss>
