generate java spring crud app with spring Initializr

Java Spring Boot

Crud App with Spring Boot

Objective

In this tutorial, I will show you how to build a crud app using Spring Boot .

Environment

Java

Spring boot

Mysql

Spring Boot

  • Java version
java -version
java version
java spring Initializr crud app
  • Generate Java Spring App
generate java spring crud app with spring Initializr

  • Open Java Spring App with IntelliJ IDEA
open java spring app with intelliJ IDEA
  • Add model repository controller exception packages
Add model controller repository exception packages
  • Add User class
New model User Class
user class java
  • Add UserRepository
Add interface UserRepository

UserRepository interface
  • Mysql workbench
create database data;
  • configure database connection with JDBC driver application.properties
application properties
  • Run Spring Boot
run spring boot app
  • Result MySQL Workbench
show databases;
mysql workbench database

use data;
desc user;
mysql data user table see columns
  • Add UserController class to send data in the database with postMapping

Add UserController Class to send data in database with postMapping

UserController Class spring postMapping

  • Run java spring boot port 8080
run java spring app tomcat port 8080
  • Postman: create a new collection
postman create new collection
  • new request send POST user localhost port 8080
new request send POST user localhost port 8080
  • view data in MySQL Workbench select from user
view data in MySQL Workbench select from user
  • GetMapping for getting data from the database
spring boot GetMapping for getting data from database

  • new request Postman get users localhost port 8080
new request send get users localhost port 8080
  • GetMapping: view user by id
getMapping find user by id
  • Exception
user not found exception java

user not found advice java
  • Test view user by Postman
view user by i postman
view user by id not found error msg postman
  • PutMapping spring: edit user by id
Put Mapping edit user by id
postman update user by id
edit user by id error message user not found postman
  • Delete Mappin spring: delete a user by id
DeleteMapping spring delete user by id
  • delete user by id postman
delete user by id postman
delete user by id not found postman
result delete user mysql Wokbench
chevron_left
chevron_right