#SpringbootJqueryAjaxCrud #SpringbootAjaxCrud #SpringbootAjaxbootstrap #SpringbootAjax
In this tutorial i will show you how to create crud functionality using springboot, bootstrap and jquery(ajax)
How to create crud operation using springboot, bootstrap and jquery(ajax)
Prerequisite
1. already familiar create api using springboot
2. already familiar containerized postgres(if you not familiar see this video = https://youtu.be/cywEQcL819E)
3. admin lte template
4. intellij idea
5. db client (i using dbeaver)
Rule
1. in this tutorial i will create springboot app only two layer(because no business layer nedeed/service layer in this tutorial)
2. i will create crud operation using jquery and front end framework using bootstrap(using admin lte template)
Let's jump right in
WARMUP
1. Download admin lte template from this website(https://github.com/ColorlibHQ/AdminLTE)
2. create springboot app using (https://start.spring.io/) if you familiar with this you can jump to the next step
3. dependency needed (jpa. thymeleaf, starter web, postgres, devtools, lombok(dependency to reduce boiler plate))
4. generate app and import to intellij idea
CORE PART - 1
1. create js, css and images folder manually(follow my step)
2. Open simple.html template (follow this path /AdminLTE-master/pages/tables) from your admin lte downloaded before
3. add css and js into your project(folow my step)
4. create crud.html, add thymeleaf(xmlns:th="http://www.thymeleaf.org"), and load js and css to the crud.html( th:href="@your path css/js)
5. back to simple.html (cut of template start from Content Wrapper and add to crud.html)
6. create package controller, entity and repository
7. open application.properties
customize your database connection with your db(already created using postgresql and run on container)
# Thymeleaf
spring.thymeleaf.cache=false
spring.thymeleaf.mode=HTML
#connect to database
spring.datasource.url=jdbc:postgresql://172.17.0.2:5432/APP_DB
spring.datasource.username=user
spring.datasource.password=password
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
7. create class controller for entry point(EntryPoint.java)
8. add this method
@GetMapping("/first-page")
public String firstPage()
return "crud";
9. try to run app
10. to make your screen full follow instruction from me
CORE PART - 2(CREATE READ/GET ALL Data from db and show in the table) my database configuration
1. create Employee entity in entity package
2. create Employee repository in repository package
3. create Employee Controller in controller package
4. create method to get all employee in EmployeeController
@GetMapping("/employees")
public List Employee getAllEmployees()
return employeeRepository.findAll();
5. create function in crud.html to get data from controller java(follow me)
6. call getEmployee in document ready jquery
7. insert data to database try to run app
8. before run, don't forget to add of name table
9. mapping json to table
CORE PART - 3(CREATE SAVE FUNCTIONALITY AND RELOAD DATA INTO TABEL AFTER SAVE)
1. create modal (for handling input user)
2. create add button, when button onclick modal show to input data
4. how to add icon in add, update and delete button? add this
3. create handling when data submitted(ajax save/create function to save data)
- get data from inputText
- convert data to Json object
- send data using ajax
4. create controller to save data
5. reload table, includes data which saved before(using ajax get which defined before) try to reload using ctrl+f9 without restart server
6. create button to handle onclick when button save clicked
Successful !!! in the next tutorial i will continue this tutorial (for part, update and delete)