Angular 7 + Spring Boot CRUD Example
In this tutorial we will be implementing CRUD operations using Angular 7 + Spring Boot. We will also be adding the header with menu and footer to our application. So following will be the components on our page.
In the next tutorial we will be implementing session management for this application and create a login and logout page.
Previously we have seen what is PCF and how to deploy application to PCF.. I have deployed this application we are developing to PCF.
Angular 7+ Spring Boot - Table of Contents
Angular 7 + Spring Boot Application Hello World Example Angular 7 + Spring Boot Application CRUD Example Angular 7 + Spring Boot Application Login Example Angular 7 + Spring Boot Application Basic Authentication Example Angular 7 + Spring Boot Basic Auth Using HTTPInterceptor Example Angular 7 + Spring Boot JWT Authentication Hello World Example
Video
This tutorial is explained in the below Youtube Video.-
Spring Boot Application
Previous application we had created a simple spring boot application which exposed a REST endpoint for fetching a list of employees. In this tutorial we will be adding 2 more REST endpoints - One for creating an employee and other for deleting it.package com.javainuse.controllers; import java.util.ArrayList; import java.util.List; import org.springframework.web.bind.annotation.CrossOrigin; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import com.javainuse.model.Employee; @CrossOrigin(origins = "http://localhost:4200") @RestController @RequestMapping({ "/employees" }) public class TestController { private List<Employee> employees = createList(); @GetMapping(produces = "application/json") public List<Employee> firstPage() { return employees; } @DeleteMapping(path = { "/{id}" }) public Employee delete(@PathVariable("id") int id) { Employee deletedEmp = null; for (Employee emp : employees) { if (emp.getEmpId().equals(id)) { employees.remove(emp); deletedEmp = emp; break; } } return deletedEmp; } @PostMapping public Employee create(@RequestBody Employee user) { employees.add(user); System.out.println(employees); return user; } private static List<Employee> createList() { List<Employee> tempEmployees = new ArrayList<>(); Employee emp1 = new Employee(); emp1.setName("emp1"); emp1.setDesignation("manager"); emp1.setEmpId("1"); emp1.setSalary(3000); Employee emp2 = new Employee(); emp2.setName("emp2"); emp2.setDesignation("developer"); emp2.setEmpId("2"); emp2.setSalary(3000); tempEmployees.add(emp1); tempEmployees.add(emp2); return tempEmployees; } }