├── README.md ├── angular9-springboot-client ├── .editorconfig ├── .gitignore ├── README.md ├── angular.json ├── browserslist ├── e2e │ ├── protractor.conf.js │ ├── src │ │ ├── app.e2e-spec.ts │ │ └── app.po.ts │ └── tsconfig.json ├── karma.conf.js ├── package-lock.json ├── package.json ├── src │ ├── app │ │ ├── app-routing.module.ts │ │ ├── app.component.css │ │ ├── app.component.html │ │ ├── app.component.spec.ts │ │ ├── app.component.ts │ │ ├── app.module.ts │ │ ├── create-employee │ │ │ ├── create-employee.component.css │ │ │ ├── create-employee.component.html │ │ │ ├── create-employee.component.spec.ts │ │ │ └── create-employee.component.ts │ │ ├── employee-details │ │ │ ├── employee-details.component.css │ │ │ ├── employee-details.component.html │ │ │ ├── employee-details.component.spec.ts │ │ │ └── employee-details.component.ts │ │ ├── employee-list │ │ │ ├── employee-list.component.css │ │ │ ├── employee-list.component.html │ │ │ ├── employee-list.component.spec.ts │ │ │ └── employee-list.component.ts │ │ ├── employee.service.spec.ts │ │ ├── employee.service.ts │ │ ├── employee.spec.ts │ │ ├── employee.ts │ │ ├── employee.ts.ts │ │ └── update-employee │ │ │ ├── update-employee.component.css │ │ │ ├── update-employee.component.html │ │ │ ├── update-employee.component.spec.ts │ │ │ └── update-employee.component.ts │ ├── assets │ │ └── .gitkeep │ ├── environments │ │ ├── environment.prod.ts │ │ └── environment.ts │ ├── favicon.ico │ ├── index.html │ ├── main.ts │ ├── polyfills.ts │ ├── styles.css │ └── test.ts ├── tsconfig.app.json ├── tsconfig.json ├── tsconfig.spec.json └── tslint.json └── springboot2-jpa-crud-example ├── .gitignore ├── .mvn └── wrapper │ ├── maven-wrapper.jar │ └── maven-wrapper.properties ├── mvnw ├── mvnw.cmd ├── pom.xml └── src ├── main ├── java │ └── net │ │ └── guides │ │ └── springboot2 │ │ └── springboot2jpacrudexample │ │ ├── Application.java │ │ ├── controller │ │ └── EmployeeController.java │ │ ├── exception │ │ ├── ErrorDetails.java │ │ ├── GlobalExceptionHandler.java │ │ └── ResourceNotFoundException.java │ │ ├── model │ │ └── Employee.java │ │ └── repository │ │ └── EmployeeRepository.java └── resources │ └── application.properties └── test └── java └── net └── guides └── springboot2 └── springboot2jpacrudexample ├── ApplicationTests.java └── EmployeeControllerIntegrationTest.java /README.md: -------------------------------------------------------------------------------- 1 | # Angular9-SpringBoot-CRUD-Tutorial 2 | 3 | Angular9-SpringBoot-CRUD-Tutorial - https://www.javaguides.net/2020/01/spring-boot-angular-9-crud-example-tutorial.html 4 | -------------------------------------------------------------------------------- /angular9-springboot-client/.editorconfig: -------------------------------------------------------------------------------- 1 | # Editor configuration, see https://editorconfig.org 2 | root = true 3 | 4 | [*] 5 | charset = utf-8 6 | indent_style = space 7 | indent_size = 2 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | 11 | [*.md] 12 | max_line_length = off 13 | trim_trailing_whitespace = false 14 | -------------------------------------------------------------------------------- /angular9-springboot-client/.gitignore: -------------------------------------------------------------------------------- 1 | # See http://help.github.com/ignore-files/ for more about ignoring files. 2 | 3 | # compiled output 4 | /dist 5 | /tmp 6 | /out-tsc 7 | # Only exists if Bazel was run 8 | /bazel-out 9 | 10 | # dependencies 11 | /node_modules 12 | 13 | # profiling files 14 | chrome-profiler-events*.json 15 | speed-measure-plugin*.json 16 | 17 | # IDEs and editors 18 | /.idea 19 | .project 20 | .classpath 21 | .c9/ 22 | *.launch 23 | .settings/ 24 | *.sublime-workspace 25 | 26 | # IDE - VSCode 27 | .vscode/* 28 | !.vscode/settings.json 29 | !.vscode/tasks.json 30 | !.vscode/launch.json 31 | !.vscode/extensions.json 32 | .history/* 33 | 34 | # misc 35 | /.sass-cache 36 | /connect.lock 37 | /coverage 38 | /libpeerconnection.log 39 | npm-debug.log 40 | yarn-error.log 41 | testem.log 42 | /typings 43 | 44 | # System Files 45 | .DS_Store 46 | Thumbs.db 47 | -------------------------------------------------------------------------------- /angular9-springboot-client/README.md: -------------------------------------------------------------------------------- 1 | # Angular9SpringbootClient 2 | 3 | This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 9.0.0-rc.7. 4 | 5 | ## Development server 6 | 7 | Run `ng serve` for a dev server. Navigate to `http://localhost:4200/`. The app will automatically reload if you change any of the source files. 8 | 9 | ## Code scaffolding 10 | 11 | Run `ng generate component component-name` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module`. 12 | 13 | ## Build 14 | 15 | Run `ng build` to build the project. The build artifacts will be stored in the `dist/` directory. Use the `--prod` flag for a production build. 16 | 17 | ## Running unit tests 18 | 19 | Run `ng test` to execute the unit tests via [Karma](https://karma-runner.github.io). 20 | 21 | ## Running end-to-end tests 22 | 23 | Run `ng e2e` to execute the end-to-end tests via [Protractor](http://www.protractortest.org/). 24 | 25 | ## Further help 26 | 27 | To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI README](https://github.com/angular/angular-cli/blob/master/README.md). 28 | -------------------------------------------------------------------------------- /angular9-springboot-client/angular.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "./node_modules/@angular/cli/lib/config/schema.json", 3 | "version": 1, 4 | "newProjectRoot": "projects", 5 | "projects": { 6 | "angular9-springboot-client": { 7 | "projectType": "application", 8 | "schematics": {}, 9 | "root": "", 10 | "sourceRoot": "src", 11 | "prefix": "app", 12 | "architect": { 13 | "build": { 14 | "builder": "@angular-devkit/build-angular:browser", 15 | "options": { 16 | "outputPath": "dist/angular9-springboot-client", 17 | "index": "src/index.html", 18 | "main": "src/main.ts", 19 | "polyfills": "src/polyfills.ts", 20 | "tsConfig": "tsconfig.app.json", 21 | "aot": true, 22 | "assets": [ 23 | "src/favicon.ico", 24 | "src/assets" 25 | ], 26 | "styles": [ 27 | "src/styles.css" 28 | ], 29 | "scripts": [] 30 | }, 31 | "configurations": { 32 | "production": { 33 | "fileReplacements": [ 34 | { 35 | "replace": "src/environments/environment.ts", 36 | "with": "src/environments/environment.prod.ts" 37 | } 38 | ], 39 | "optimization": true, 40 | "outputHashing": "all", 41 | "sourceMap": false, 42 | "extractCss": true, 43 | "namedChunks": false, 44 | "extractLicenses": true, 45 | "vendorChunk": false, 46 | "buildOptimizer": true, 47 | "budgets": [ 48 | { 49 | "type": "initial", 50 | "maximumWarning": "2mb", 51 | "maximumError": "5mb" 52 | }, 53 | { 54 | "type": "anyComponentStyle", 55 | "maximumWarning": "6kb", 56 | "maximumError": "10kb" 57 | } 58 | ] 59 | } 60 | } 61 | }, 62 | "serve": { 63 | "builder": "@angular-devkit/build-angular:dev-server", 64 | "options": { 65 | "browserTarget": "angular9-springboot-client:build" 66 | }, 67 | "configurations": { 68 | "production": { 69 | "browserTarget": "angular9-springboot-client:build:production" 70 | } 71 | } 72 | }, 73 | "extract-i18n": { 74 | "builder": "@angular-devkit/build-angular:extract-i18n", 75 | "options": { 76 | "browserTarget": "angular9-springboot-client:build" 77 | } 78 | }, 79 | "test": { 80 | "builder": "@angular-devkit/build-angular:karma", 81 | "options": { 82 | "main": "src/test.ts", 83 | "polyfills": "src/polyfills.ts", 84 | "tsConfig": "tsconfig.spec.json", 85 | "karmaConfig": "karma.conf.js", 86 | "assets": [ 87 | "src/favicon.ico", 88 | "src/assets" 89 | ], 90 | "styles": [ 91 | "src/styles.css" 92 | ], 93 | "scripts": [] 94 | } 95 | }, 96 | "lint": { 97 | "builder": "@angular-devkit/build-angular:tslint", 98 | "options": { 99 | "tsConfig": [ 100 | "tsconfig.app.json", 101 | "tsconfig.spec.json", 102 | "e2e/tsconfig.json" 103 | ], 104 | "exclude": [ 105 | "**/node_modules/**" 106 | ] 107 | } 108 | }, 109 | "e2e": { 110 | "builder": "@angular-devkit/build-angular:protractor", 111 | "options": { 112 | "protractorConfig": "e2e/protractor.conf.js", 113 | "devServerTarget": "angular9-springboot-client:serve" 114 | }, 115 | "configurations": { 116 | "production": { 117 | "devServerTarget": "angular9-springboot-client:serve:production" 118 | } 119 | } 120 | } 121 | } 122 | }}, 123 | "defaultProject": "angular9-springboot-client" 124 | } 125 | -------------------------------------------------------------------------------- /angular9-springboot-client/browserslist: -------------------------------------------------------------------------------- 1 | # This file is used by the build system to adjust CSS and JS output to support the specified browsers below. 2 | # For additional information regarding the format and rule options, please see: 3 | # https://github.com/browserslist/browserslist#queries 4 | 5 | # You can see what browsers were selected by your queries by running: 6 | # npx browserslist 7 | 8 | > 0.5% 9 | last 2 versions 10 | Firefox ESR 11 | not dead 12 | not IE 9-11 # For IE 9-11 support, remove 'not'. -------------------------------------------------------------------------------- /angular9-springboot-client/e2e/protractor.conf.js: -------------------------------------------------------------------------------- 1 | // @ts-check 2 | // Protractor configuration file, see link for more information 3 | // https://github.com/angular/protractor/blob/master/lib/config.ts 4 | 5 | const { SpecReporter } = require('jasmine-spec-reporter'); 6 | 7 | /** 8 | * @type { import("protractor").Config } 9 | */ 10 | exports.config = { 11 | allScriptsTimeout: 11000, 12 | specs: [ 13 | './src/**/*.e2e-spec.ts' 14 | ], 15 | capabilities: { 16 | browserName: 'chrome' 17 | }, 18 | directConnect: true, 19 | baseUrl: 'http://localhost:4200/', 20 | framework: 'jasmine', 21 | jasmineNodeOpts: { 22 | showColors: true, 23 | defaultTimeoutInterval: 30000, 24 | print: function() {} 25 | }, 26 | onPrepare() { 27 | require('ts-node').register({ 28 | project: require('path').join(__dirname, './tsconfig.json') 29 | }); 30 | jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } })); 31 | } 32 | }; -------------------------------------------------------------------------------- /angular9-springboot-client/e2e/src/app.e2e-spec.ts: -------------------------------------------------------------------------------- 1 | import { AppPage } from './app.po'; 2 | import { browser, logging } from 'protractor'; 3 | 4 | describe('workspace-project App', () => { 5 | let page: AppPage; 6 | 7 | beforeEach(() => { 8 | page = new AppPage(); 9 | }); 10 | 11 | it('should display welcome message', () => { 12 | page.navigateTo(); 13 | expect(page.getTitleText()).toEqual('angular9-springboot-client app is running!'); 14 | }); 15 | 16 | afterEach(async () => { 17 | // Assert that there are no errors emitted from the browser 18 | const logs = await browser.manage().logs().get(logging.Type.BROWSER); 19 | expect(logs).not.toContain(jasmine.objectContaining({ 20 | level: logging.Level.SEVERE, 21 | } as logging.Entry)); 22 | }); 23 | }); 24 | -------------------------------------------------------------------------------- /angular9-springboot-client/e2e/src/app.po.ts: -------------------------------------------------------------------------------- 1 | import { browser, by, element } from 'protractor'; 2 | 3 | export class AppPage { 4 | navigateTo() { 5 | return browser.get(browser.baseUrl) as Promise; 6 | } 7 | 8 | getTitleText() { 9 | return element(by.css('app-root .content span')).getText() as Promise; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /angular9-springboot-client/e2e/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/e2e", 5 | "module": "commonjs", 6 | "target": "es5", 7 | "types": [ 8 | "jasmine", 9 | "jasminewd2", 10 | "node" 11 | ] 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /angular9-springboot-client/karma.conf.js: -------------------------------------------------------------------------------- 1 | // Karma configuration file, see link for more information 2 | // https://karma-runner.github.io/1.0/config/configuration-file.html 3 | 4 | module.exports = function (config) { 5 | config.set({ 6 | basePath: '', 7 | frameworks: ['jasmine', '@angular-devkit/build-angular'], 8 | plugins: [ 9 | require('karma-jasmine'), 10 | require('karma-chrome-launcher'), 11 | require('karma-jasmine-html-reporter'), 12 | require('karma-coverage-istanbul-reporter'), 13 | require('@angular-devkit/build-angular/plugins/karma') 14 | ], 15 | client: { 16 | clearContext: false // leave Jasmine Spec Runner output visible in browser 17 | }, 18 | coverageIstanbulReporter: { 19 | dir: require('path').join(__dirname, './coverage/angular9-springboot-client'), 20 | reports: ['html', 'lcovonly', 'text-summary'], 21 | fixWebpackSourcePaths: true 22 | }, 23 | reporters: ['progress', 'kjhtml'], 24 | port: 9876, 25 | colors: true, 26 | logLevel: config.LOG_INFO, 27 | autoWatch: true, 28 | browsers: ['Chrome'], 29 | singleRun: false, 30 | restartOnFileChange: true 31 | }); 32 | }; 33 | -------------------------------------------------------------------------------- /angular9-springboot-client/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "angular9-springboot-client", 3 | "version": "0.0.0", 4 | "scripts": { 5 | "ng": "ng", 6 | "start": "ng serve", 7 | "build": "ng build", 8 | "test": "ng test", 9 | "lint": "ng lint", 10 | "e2e": "ng e2e" 11 | }, 12 | "private": true, 13 | "dependencies": { 14 | "@angular/animations": "~9.0.0-rc.7", 15 | "@angular/common": "~9.0.0-rc.7", 16 | "@angular/compiler": "~9.0.0-rc.7", 17 | "@angular/core": "~9.0.0-rc.7", 18 | "@angular/forms": "~9.0.0-rc.7", 19 | "@angular/platform-browser": "~9.0.0-rc.7", 20 | "@angular/platform-browser-dynamic": "~9.0.0-rc.7", 21 | "@angular/router": "~9.0.0-rc.7", 22 | "bootstrap": "^4.4.1", 23 | "jquery": "^3.4.1", 24 | "rxjs": "~6.5.3", 25 | "tslib": "^1.10.0", 26 | "zone.js": "~0.10.2" 27 | }, 28 | "devDependencies": { 29 | "@angular-devkit/build-angular": "~0.900.0-rc.7", 30 | "@angular/cli": "~9.0.0-rc.7", 31 | "@angular/compiler-cli": "~9.0.0-rc.7", 32 | "@angular/language-service": "~9.0.0-rc.7", 33 | "@types/node": "^12.11.1", 34 | "@types/jasmine": "~3.5.0", 35 | "@types/jasminewd2": "~2.0.3", 36 | "codelyzer": "^5.1.2", 37 | "jasmine-core": "~3.5.0", 38 | "jasmine-spec-reporter": "~4.2.1", 39 | "karma": "~4.3.0", 40 | "karma-chrome-launcher": "~3.1.0", 41 | "karma-coverage-istanbul-reporter": "~2.1.0", 42 | "karma-jasmine": "~2.0.1", 43 | "karma-jasmine-html-reporter": "^1.4.2", 44 | "protractor": "~5.4.2", 45 | "ts-node": "~8.3.0", 46 | "tslint": "~5.18.0", 47 | "typescript": "~3.6.4" 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /angular9-springboot-client/src/app/app-routing.module.ts: -------------------------------------------------------------------------------- 1 | import { EmployeeDetailsComponent } from './employee-details/employee-details.component'; 2 | import { CreateEmployeeComponent } from './create-employee/create-employee.component'; 3 | import { NgModule } from '@angular/core'; 4 | import { Routes, RouterModule } from '@angular/router'; 5 | import { EmployeeListComponent } from './employee-list/employee-list.component'; 6 | import { UpdateEmployeeComponent } from './update-employee/update-employee.component'; 7 | 8 | const routes: Routes = [ 9 | { path: '', redirectTo: 'employee', pathMatch: 'full' }, 10 | { path: 'employees', component: EmployeeListComponent }, 11 | { path: 'add', component: CreateEmployeeComponent }, 12 | { path: 'update/:id', component: UpdateEmployeeComponent }, 13 | { path: 'details/:id', component: EmployeeDetailsComponent }, 14 | ]; 15 | 16 | @NgModule({ 17 | imports: [RouterModule.forRoot(routes)], 18 | exports: [RouterModule] 19 | }) 20 | export class AppRoutingModule { } 21 | -------------------------------------------------------------------------------- /angular9-springboot-client/src/app/app.component.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RameshMF/Angular9-SpringBoot-CRUD-Tutorial/4be8b04bca02813850ce8f3ef25d11841ddc4853/angular9-springboot-client/src/app/app.component.css -------------------------------------------------------------------------------- /angular9-springboot-client/src/app/app.component.html: -------------------------------------------------------------------------------- 1 | 12 | 13 | 14 |
15 |
16 |

{{title}}

17 |
18 |
19 |
20 | 21 |
22 |
23 |
24 | 25 |
26 |
27 | All Rights Reserved 2019 @JavaGuides 28 |
29 |
-------------------------------------------------------------------------------- /angular9-springboot-client/src/app/app.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { TestBed, async } from '@angular/core/testing'; 2 | import { RouterTestingModule } from '@angular/router/testing'; 3 | import { AppComponent } from './app.component'; 4 | 5 | describe('AppComponent', () => { 6 | beforeEach(async(() => { 7 | TestBed.configureTestingModule({ 8 | imports: [ 9 | RouterTestingModule 10 | ], 11 | declarations: [ 12 | AppComponent 13 | ], 14 | }).compileComponents(); 15 | })); 16 | 17 | it('should create the app', () => { 18 | const fixture = TestBed.createComponent(AppComponent); 19 | const app = fixture.debugElement.componentInstance; 20 | expect(app).toBeTruthy(); 21 | }); 22 | 23 | it(`should have as title 'angular6-springboot-client'`, () => { 24 | const fixture = TestBed.createComponent(AppComponent); 25 | const app = fixture.debugElement.componentInstance; 26 | expect(app.title).toEqual('angular6-springboot-client'); 27 | }); 28 | 29 | it('should render title in a h1 tag', () => { 30 | const fixture = TestBed.createComponent(AppComponent); 31 | fixture.detectChanges(); 32 | const compiled = fixture.debugElement.nativeElement; 33 | expect(compiled.querySelector('h1').textContent).toContain('Welcome to angular6-springboot-client!'); 34 | }); 35 | }); 36 | -------------------------------------------------------------------------------- /angular9-springboot-client/src/app/app.component.ts: -------------------------------------------------------------------------------- 1 | import { Component } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'app-root', 5 | templateUrl: './app.component.html', 6 | styleUrls: ['./app.component.css'] 7 | }) 8 | export class AppComponent { 9 | title = 'Angular 9 + Spring Boot 2 CRUD Tutorial'; 10 | } 11 | -------------------------------------------------------------------------------- /angular9-springboot-client/src/app/app.module.ts: -------------------------------------------------------------------------------- 1 | import { BrowserModule } from '@angular/platform-browser'; 2 | import { NgModule } from '@angular/core'; 3 | import { FormsModule } from '@angular/forms'; 4 | import { AppRoutingModule } from './app-routing.module'; 5 | import { AppComponent } from './app.component'; 6 | import { CreateEmployeeComponent } from './create-employee/create-employee.component'; 7 | import { EmployeeDetailsComponent } from './employee-details/employee-details.component'; 8 | import { EmployeeListComponent } from './employee-list/employee-list.component'; 9 | import { HttpClientModule } from '@angular/common/http'; 10 | import { UpdateEmployeeComponent } from './update-employee/update-employee.component'; 11 | @NgModule({ 12 | declarations: [ 13 | AppComponent, 14 | CreateEmployeeComponent, 15 | EmployeeDetailsComponent, 16 | EmployeeListComponent, 17 | UpdateEmployeeComponent 18 | ], 19 | imports: [ 20 | BrowserModule, 21 | AppRoutingModule, 22 | FormsModule, 23 | HttpClientModule 24 | ], 25 | providers: [], 26 | bootstrap: [AppComponent] 27 | }) 28 | export class AppModule { } 29 | -------------------------------------------------------------------------------- /angular9-springboot-client/src/app/create-employee/create-employee.component.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RameshMF/Angular9-SpringBoot-CRUD-Tutorial/4be8b04bca02813850ce8f3ef25d11841ddc4853/angular9-springboot-client/src/app/create-employee/create-employee.component.css -------------------------------------------------------------------------------- /angular9-springboot-client/src/app/create-employee/create-employee.component.html: -------------------------------------------------------------------------------- 1 |

Create Employee

2 |
3 |
4 |
5 | 6 | 7 |
8 | 9 |
10 | 11 | 12 |
13 | 14 |
15 | 16 | 17 |
18 | 19 | 20 |
21 |
22 | 23 |
24 |

You submitted successfully!

25 | 26 |
27 | -------------------------------------------------------------------------------- /angular9-springboot-client/src/app/create-employee/create-employee.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { CreateEmployeeComponent } from './create-employee.component'; 4 | 5 | describe('CreateEmployeeComponent', () => { 6 | let component: CreateEmployeeComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ CreateEmployeeComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(CreateEmployeeComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /angular9-springboot-client/src/app/create-employee/create-employee.component.ts: -------------------------------------------------------------------------------- 1 | import { EmployeeService } from '../employee.service'; 2 | import { Employee } from '../employee'; 3 | import { Component, OnInit } from '@angular/core'; 4 | import { Router } from '@angular/router'; 5 | 6 | @Component({ 7 | selector: 'app-create-employee', 8 | templateUrl: './create-employee.component.html', 9 | styleUrls: ['./create-employee.component.css'] 10 | }) 11 | export class CreateEmployeeComponent implements OnInit { 12 | 13 | employee: Employee = new Employee(); 14 | submitted = false; 15 | 16 | constructor(private employeeService: EmployeeService, 17 | private router: Router) { } 18 | 19 | ngOnInit() { 20 | } 21 | 22 | newEmployee(): void { 23 | this.submitted = false; 24 | this.employee = new Employee(); 25 | } 26 | 27 | save() { 28 | this.employeeService 29 | .createEmployee(this.employee).subscribe(data => { 30 | console.log(data) 31 | this.employee = new Employee(); 32 | this.gotoList(); 33 | }, 34 | error => console.log(error)); 35 | } 36 | 37 | onSubmit() { 38 | this.submitted = true; 39 | this.save(); 40 | } 41 | 42 | gotoList() { 43 | this.router.navigate(['/employees']); 44 | } 45 | } -------------------------------------------------------------------------------- /angular9-springboot-client/src/app/employee-details/employee-details.component.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RameshMF/Angular9-SpringBoot-CRUD-Tutorial/4be8b04bca02813850ce8f3ef25d11841ddc4853/angular9-springboot-client/src/app/employee-details/employee-details.component.css -------------------------------------------------------------------------------- /angular9-springboot-client/src/app/employee-details/employee-details.component.html: -------------------------------------------------------------------------------- 1 |

Employee Details

2 | 3 |
4 |
5 |
6 | {{employee.firstName}} 7 |
8 |
9 | {{employee.lastName}} 10 |
11 |
12 | {{employee.emailId}} 13 |
14 |
15 | 16 |
17 |
18 |
19 | 20 | 21 | -------------------------------------------------------------------------------- /angular9-springboot-client/src/app/employee-details/employee-details.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { EmployeeDetailsComponent } from './employee-details.component'; 4 | 5 | describe('EmployeeDetailsComponent', () => { 6 | let component: EmployeeDetailsComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ EmployeeDetailsComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(EmployeeDetailsComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /angular9-springboot-client/src/app/employee-details/employee-details.component.ts: -------------------------------------------------------------------------------- 1 | import { Employee } from '../employee'; 2 | import { Component, OnInit, Input } from '@angular/core'; 3 | import { EmployeeService } from '../employee.service'; 4 | import { EmployeeListComponent } from '../employee-list/employee-list.component'; 5 | import { Router, ActivatedRoute } from '@angular/router'; 6 | 7 | @Component({ 8 | selector: 'app-employee-details', 9 | templateUrl: './employee-details.component.html', 10 | styleUrls: ['./employee-details.component.css'] 11 | }) 12 | export class EmployeeDetailsComponent implements OnInit { 13 | 14 | id: number; 15 | employee: Employee; 16 | 17 | constructor(private route: ActivatedRoute,private router: Router, 18 | private employeeService: EmployeeService) { } 19 | 20 | ngOnInit() { 21 | this.employee = new Employee(); 22 | 23 | this.id = this.route.snapshot.params['id']; 24 | 25 | this.employeeService.getEmployee(this.id) 26 | .subscribe(data => { 27 | console.log(data) 28 | this.employee = data; 29 | }, error => console.log(error)); 30 | } 31 | 32 | list(){ 33 | this.router.navigate(['employees']); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /angular9-springboot-client/src/app/employee-list/employee-list.component.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RameshMF/Angular9-SpringBoot-CRUD-Tutorial/4be8b04bca02813850ce8f3ef25d11841ddc4853/angular9-springboot-client/src/app/employee-list/employee-list.component.css -------------------------------------------------------------------------------- /angular9-springboot-client/src/app/employee-list/employee-list.component.html: -------------------------------------------------------------------------------- 1 |
2 |
3 |

Employee List

4 |
5 |
6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 24 | 25 | 26 |
FirstnameLastnameEmailActions
{{employee.firstName}}{{employee.lastName}}{{employee.emailId}} 21 | 22 | 23 |
27 |
28 |
29 | 30 | -------------------------------------------------------------------------------- /angular9-springboot-client/src/app/employee-list/employee-list.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { EmployeeListComponent } from './employee-list.component'; 4 | 5 | describe('EmployeeListComponent', () => { 6 | let component: EmployeeListComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ EmployeeListComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(EmployeeListComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /angular9-springboot-client/src/app/employee-list/employee-list.component.ts: -------------------------------------------------------------------------------- 1 | import { EmployeeDetailsComponent } from './../employee-details/employee-details.component'; 2 | import { Observable } from "rxjs"; 3 | import { EmployeeService } from "./../employee.service"; 4 | import { Employee } from "./../employee"; 5 | import { Component, OnInit } from "@angular/core"; 6 | import { Router } from '@angular/router'; 7 | 8 | @Component({ 9 | selector: "app-employee-list", 10 | templateUrl: "./employee-list.component.html", 11 | styleUrls: ["./employee-list.component.css"] 12 | }) 13 | export class EmployeeListComponent implements OnInit { 14 | employees: Observable; 15 | 16 | constructor(private employeeService: EmployeeService, 17 | private router: Router) {} 18 | 19 | ngOnInit() { 20 | this.reloadData(); 21 | } 22 | 23 | reloadData() { 24 | this.employees = this.employeeService.getEmployeesList(); 25 | } 26 | 27 | deleteEmployee(id: number) { 28 | this.employeeService.deleteEmployee(id) 29 | .subscribe( 30 | data => { 31 | console.log(data); 32 | this.reloadData(); 33 | }, 34 | error => console.log(error)); 35 | } 36 | 37 | employeeDetails(id: number){ 38 | this.router.navigate(['details', id]); 39 | } 40 | 41 | updateEmployee(id: number){ 42 | this.router.navigate(['update', id]); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /angular9-springboot-client/src/app/employee.service.spec.ts: -------------------------------------------------------------------------------- 1 | import { TestBed } from '@angular/core/testing'; 2 | 3 | import { EmployeeService } from './employee.service'; 4 | 5 | describe('EmployeeService', () => { 6 | beforeEach(() => TestBed.configureTestingModule({})); 7 | 8 | it('should be created', () => { 9 | const service: EmployeeService = TestBed.get(EmployeeService); 10 | expect(service).toBeTruthy(); 11 | }); 12 | }); 13 | -------------------------------------------------------------------------------- /angular9-springboot-client/src/app/employee.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | import { HttpClient } from '@angular/common/http'; 3 | import { Observable } from 'rxjs'; 4 | 5 | @Injectable({ 6 | providedIn: 'root' 7 | }) 8 | export class EmployeeService { 9 | 10 | private baseUrl = 'http://localhost:8080/springboot-crud-rest/api/v1/employees'; 11 | 12 | constructor(private http: HttpClient) { } 13 | 14 | getEmployee(id: number): Observable { 15 | return this.http.get(`${this.baseUrl}/${id}`); 16 | } 17 | 18 | createEmployee(employee: Object): Observable { 19 | return this.http.post(`${this.baseUrl}`, employee); 20 | } 21 | 22 | updateEmployee(id: number, value: any): Observable { 23 | return this.http.put(`${this.baseUrl}/${id}`, value); 24 | } 25 | 26 | deleteEmployee(id: number): Observable { 27 | return this.http.delete(`${this.baseUrl}/${id}`, { responseType: 'text' }); 28 | } 29 | 30 | getEmployeesList(): Observable { 31 | return this.http.get(`${this.baseUrl}`); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /angular9-springboot-client/src/app/employee.spec.ts: -------------------------------------------------------------------------------- 1 | import { Employee } from './employee'; 2 | 3 | describe('Employee', () => { 4 | it('should create an instance', () => { 5 | expect(new Employee()).toBeTruthy(); 6 | }); 7 | }); 8 | -------------------------------------------------------------------------------- /angular9-springboot-client/src/app/employee.ts: -------------------------------------------------------------------------------- 1 | export class Employee { 2 | id: number; 3 | firstName: string; 4 | lastName: string; 5 | emailId: string; 6 | active: boolean; 7 | } 8 | -------------------------------------------------------------------------------- /angular9-springboot-client/src/app/employee.ts.ts: -------------------------------------------------------------------------------- 1 | export class Employee { 2 | id: number; 3 | firstName: string; 4 | lastName: string; 5 | emailId: string; 6 | active: boolean; 7 | } -------------------------------------------------------------------------------- /angular9-springboot-client/src/app/update-employee/update-employee.component.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RameshMF/Angular9-SpringBoot-CRUD-Tutorial/4be8b04bca02813850ce8f3ef25d11841ddc4853/angular9-springboot-client/src/app/update-employee/update-employee.component.css -------------------------------------------------------------------------------- /angular9-springboot-client/src/app/update-employee/update-employee.component.html: -------------------------------------------------------------------------------- 1 |

Update Employee

2 |
3 |
4 |
5 | 6 | 7 |
8 | 9 |
10 | 11 | 12 |
13 | 14 |
15 | 16 | 17 |
18 | 19 | 20 |
21 |
22 | -------------------------------------------------------------------------------- /angular9-springboot-client/src/app/update-employee/update-employee.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { UpdateEmployeeComponent } from './update-employee.component'; 4 | 5 | describe('UpdateEmployeeComponent', () => { 6 | let component: UpdateEmployeeComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ UpdateEmployeeComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(UpdateEmployeeComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /angular9-springboot-client/src/app/update-employee/update-employee.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import { Employee } from '../employee'; 3 | import { ActivatedRoute, Router } from '@angular/router'; 4 | import { EmployeeService } from '../employee.service'; 5 | 6 | @Component({ 7 | selector: 'app-update-employee', 8 | templateUrl: './update-employee.component.html', 9 | styleUrls: ['./update-employee.component.css'] 10 | }) 11 | export class UpdateEmployeeComponent implements OnInit { 12 | 13 | id: number; 14 | employee: Employee; 15 | 16 | constructor(private route: ActivatedRoute,private router: Router, 17 | private employeeService: EmployeeService) { } 18 | 19 | ngOnInit() { 20 | this.employee = new Employee(); 21 | 22 | this.id = this.route.snapshot.params['id']; 23 | 24 | this.employeeService.getEmployee(this.id) 25 | .subscribe(data => { 26 | console.log(data) 27 | this.employee = data; 28 | }, error => console.log(error)); 29 | } 30 | 31 | updateEmployee() { 32 | this.employeeService.updateEmployee(this.id, this.employee) 33 | .subscribe(data => { 34 | console.log(data); 35 | this.employee = new Employee(); 36 | this.gotoList(); 37 | }, error => console.log(error)); 38 | } 39 | 40 | onSubmit() { 41 | this.updateEmployee(); 42 | } 43 | 44 | gotoList() { 45 | this.router.navigate(['/employees']); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /angular9-springboot-client/src/assets/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RameshMF/Angular9-SpringBoot-CRUD-Tutorial/4be8b04bca02813850ce8f3ef25d11841ddc4853/angular9-springboot-client/src/assets/.gitkeep -------------------------------------------------------------------------------- /angular9-springboot-client/src/environments/environment.prod.ts: -------------------------------------------------------------------------------- 1 | export const environment = { 2 | production: true 3 | }; 4 | -------------------------------------------------------------------------------- /angular9-springboot-client/src/environments/environment.ts: -------------------------------------------------------------------------------- 1 | // This file can be replaced during build by using the `fileReplacements` array. 2 | // `ng build --prod` replaces `environment.ts` with `environment.prod.ts`. 3 | // The list of file replacements can be found in `angular.json`. 4 | 5 | export const environment = { 6 | production: false 7 | }; 8 | 9 | /* 10 | * For easier debugging in development mode, you can import the following file 11 | * to ignore zone related error stack frames such as `zone.run`, `zoneDelegate.invokeTask`. 12 | * 13 | * This import should be commented out in production mode because it will have a negative impact 14 | * on performance if an error is thrown. 15 | */ 16 | // import 'zone.js/dist/zone-error'; // Included with Angular CLI. 17 | -------------------------------------------------------------------------------- /angular9-springboot-client/src/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RameshMF/Angular9-SpringBoot-CRUD-Tutorial/4be8b04bca02813850ce8f3ef25d11841ddc4853/angular9-springboot-client/src/favicon.ico -------------------------------------------------------------------------------- /angular9-springboot-client/src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Angular8SpringbootClient 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /angular9-springboot-client/src/main.ts: -------------------------------------------------------------------------------- 1 | import { enableProdMode } from '@angular/core'; 2 | import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; 3 | 4 | import { AppModule } from './app/app.module'; 5 | import { environment } from './environments/environment'; 6 | 7 | if (environment.production) { 8 | enableProdMode(); 9 | } 10 | 11 | platformBrowserDynamic().bootstrapModule(AppModule) 12 | .catch(err => console.error(err)); 13 | -------------------------------------------------------------------------------- /angular9-springboot-client/src/polyfills.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * This file includes polyfills needed by Angular and is loaded before the app. 3 | * You can add your own extra polyfills to this file. 4 | * 5 | * This file is divided into 2 sections: 6 | * 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers. 7 | * 2. Application imports. Files imported after ZoneJS that should be loaded before your main 8 | * file. 9 | * 10 | * The current setup is for so-called "evergreen" browsers; the last versions of browsers that 11 | * automatically update themselves. This includes Safari >= 10, Chrome >= 55 (including Opera), 12 | * Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile. 13 | * 14 | * Learn more in https://angular.io/guide/browser-support 15 | */ 16 | 17 | /*************************************************************************************************** 18 | * BROWSER POLYFILLS 19 | */ 20 | 21 | /** IE10 and IE11 requires the following for NgClass support on SVG elements */ 22 | // import 'classlist.js'; // Run `npm install --save classlist.js`. 23 | 24 | /** 25 | * Web Animations `@angular/platform-browser/animations` 26 | * Only required if AnimationBuilder is used within the application and using IE/Edge or Safari. 27 | * Standard animation support in Angular DOES NOT require any polyfills (as of Angular 6.0). 28 | */ 29 | // import 'web-animations-js'; // Run `npm install --save web-animations-js`. 30 | 31 | /** 32 | * By default, zone.js will patch all possible macroTask and DomEvents 33 | * user can disable parts of macroTask/DomEvents patch by setting following flags 34 | * because those flags need to be set before `zone.js` being loaded, and webpack 35 | * will put import in the top of bundle, so user need to create a separate file 36 | * in this directory (for example: zone-flags.ts), and put the following flags 37 | * into that file, and then add the following code before importing zone.js. 38 | * import './zone-flags.ts'; 39 | * 40 | * The flags allowed in zone-flags.ts are listed here. 41 | * 42 | * The following flags will work for all browsers. 43 | * 44 | * (window as any).__Zone_disable_requestAnimationFrame = true; // disable patch requestAnimationFrame 45 | * (window as any).__Zone_disable_on_property = true; // disable patch onProperty such as onclick 46 | * (window as any).__zone_symbol__UNPATCHED_EVENTS = ['scroll', 'mousemove']; // disable patch specified eventNames 47 | * 48 | * in IE/Edge developer tools, the addEventListener will also be wrapped by zone.js 49 | * with the following flag, it will bypass `zone.js` patch for IE/Edge 50 | * 51 | * (window as any).__Zone_enable_cross_context_check = true; 52 | * 53 | */ 54 | 55 | /*************************************************************************************************** 56 | * Zone JS is required by default for Angular itself. 57 | */ 58 | import 'zone.js/dist/zone'; // Included with Angular CLI. 59 | 60 | 61 | /*************************************************************************************************** 62 | * APPLICATION IMPORTS 63 | */ 64 | -------------------------------------------------------------------------------- /angular9-springboot-client/src/styles.css: -------------------------------------------------------------------------------- 1 | /* You can add global styles to this file, and also import other style files */ 2 | 3 | @import '~bootstrap/dist/css/bootstrap.min.css'; 4 | 5 | .footer { 6 | position: absolute; 7 | bottom: 0; 8 | width:100%; 9 | height: 70px; 10 | background-color: blue; 11 | text-align: center; 12 | color: white; 13 | } -------------------------------------------------------------------------------- /angular9-springboot-client/src/test.ts: -------------------------------------------------------------------------------- 1 | // This file is required by karma.conf.js and loads recursively all the .spec and framework files 2 | 3 | import 'zone.js/dist/zone-testing'; 4 | import { getTestBed } from '@angular/core/testing'; 5 | import { 6 | BrowserDynamicTestingModule, 7 | platformBrowserDynamicTesting 8 | } from '@angular/platform-browser-dynamic/testing'; 9 | 10 | declare const require: any; 11 | 12 | // First, initialize the Angular testing environment. 13 | getTestBed().initTestEnvironment( 14 | BrowserDynamicTestingModule, 15 | platformBrowserDynamicTesting() 16 | ); 17 | // Then we find all the tests. 18 | const context = require.context('./', true, /\.spec\.ts$/); 19 | // And load the modules. 20 | context.keys().map(context); 21 | -------------------------------------------------------------------------------- /angular9-springboot-client/tsconfig.app.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "./out-tsc/app", 5 | "types": [] 6 | }, 7 | "files": [ 8 | "src/main.ts", 9 | "src/polyfills.ts" 10 | ], 11 | "include": [ 12 | "src/**/*.d.ts" 13 | ] 14 | } 15 | -------------------------------------------------------------------------------- /angular9-springboot-client/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compileOnSave": false, 3 | "compilerOptions": { 4 | "baseUrl": "./", 5 | "outDir": "./dist", 6 | "sourceMap": true, 7 | "declaration": false, 8 | "downlevelIteration": true, 9 | "experimentalDecorators": true, 10 | "module": "esnext", 11 | "moduleResolution": "node", 12 | "importHelpers": true, 13 | "target": "es2015", 14 | "typeRoots": [ 15 | "node_modules/@types" 16 | ], 17 | "lib": [ 18 | "es2018", 19 | "dom" 20 | ] 21 | }, 22 | "angularCompilerOptions": { 23 | "fullTemplateTypeCheck": true, 24 | "strictInjectionParameters": true 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /angular9-springboot-client/tsconfig.spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "./out-tsc/spec", 5 | "types": [ 6 | "jasmine", 7 | "node" 8 | ] 9 | }, 10 | "files": [ 11 | "src/test.ts", 12 | "src/polyfills.ts" 13 | ], 14 | "include": [ 15 | "src/**/*.spec.ts", 16 | "src/**/*.d.ts" 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /angular9-springboot-client/tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "tslint:recommended", 3 | "rules": { 4 | "array-type": false, 5 | "arrow-parens": false, 6 | "deprecation": { 7 | "severity": "warning" 8 | }, 9 | "component-class-suffix": true, 10 | "contextual-lifecycle": true, 11 | "directive-class-suffix": true, 12 | "directive-selector": [ 13 | true, 14 | "attribute", 15 | "app", 16 | "camelCase" 17 | ], 18 | "component-selector": [ 19 | true, 20 | "element", 21 | "app", 22 | "kebab-case" 23 | ], 24 | "import-blacklist": [ 25 | true, 26 | "rxjs/Rx" 27 | ], 28 | "interface-name": false, 29 | "max-classes-per-file": false, 30 | "max-line-length": [ 31 | true, 32 | 140 33 | ], 34 | "member-access": false, 35 | "member-ordering": [ 36 | true, 37 | { 38 | "order": [ 39 | "static-field", 40 | "instance-field", 41 | "static-method", 42 | "instance-method" 43 | ] 44 | } 45 | ], 46 | "no-consecutive-blank-lines": false, 47 | "no-console": [ 48 | true, 49 | "debug", 50 | "info", 51 | "time", 52 | "timeEnd", 53 | "trace" 54 | ], 55 | "no-empty": false, 56 | "no-inferrable-types": [ 57 | true, 58 | "ignore-params" 59 | ], 60 | "no-non-null-assertion": true, 61 | "no-redundant-jsdoc": true, 62 | "no-switch-case-fall-through": true, 63 | "no-var-requires": false, 64 | "object-literal-key-quotes": [ 65 | true, 66 | "as-needed" 67 | ], 68 | "object-literal-sort-keys": false, 69 | "ordered-imports": false, 70 | "quotemark": [ 71 | true, 72 | "single" 73 | ], 74 | "trailing-comma": false, 75 | "no-conflicting-lifecycle": true, 76 | "no-host-metadata-property": true, 77 | "no-input-rename": true, 78 | "no-inputs-metadata-property": true, 79 | "no-output-native": true, 80 | "no-output-on-prefix": true, 81 | "no-output-rename": true, 82 | "no-outputs-metadata-property": true, 83 | "template-banana-in-box": true, 84 | "template-no-negated-async": true, 85 | "use-lifecycle-interface": true, 86 | "use-pipe-transform-interface": true 87 | }, 88 | "rulesDirectory": [ 89 | "codelyzer" 90 | ] 91 | } -------------------------------------------------------------------------------- /springboot2-jpa-crud-example/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | .sts4-cache 12 | 13 | ### IntelliJ IDEA ### 14 | .idea 15 | *.iws 16 | *.iml 17 | *.ipr 18 | 19 | ### NetBeans ### 20 | /nbproject/private/ 21 | /build/ 22 | /nbbuild/ 23 | /dist/ 24 | /nbdist/ 25 | /.nb-gradle/ -------------------------------------------------------------------------------- /springboot2-jpa-crud-example/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RameshMF/Angular9-SpringBoot-CRUD-Tutorial/4be8b04bca02813850ce8f3ef25d11841ddc4853/springboot2-jpa-crud-example/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /springboot2-jpa-crud-example/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.4/apache-maven-3.5.4-bin.zip 2 | -------------------------------------------------------------------------------- /springboot2-jpa-crud-example/mvnw: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # ---------------------------------------------------------------------------- 3 | # Licensed to the Apache Software Foundation (ASF) under one 4 | # or more contributor license agreements. See the NOTICE file 5 | # distributed with this work for additional information 6 | # regarding copyright ownership. The ASF licenses this file 7 | # to you under the Apache License, Version 2.0 (the 8 | # "License"); you may not use this file except in compliance 9 | # with the License. You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, 14 | # software distributed under the License is distributed on an 15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | # KIND, either express or implied. See the License for the 17 | # specific language governing permissions and limitations 18 | # under the License. 19 | # ---------------------------------------------------------------------------- 20 | 21 | # ---------------------------------------------------------------------------- 22 | # Maven2 Start Up Batch script 23 | # 24 | # Required ENV vars: 25 | # ------------------ 26 | # JAVA_HOME - location of a JDK home dir 27 | # 28 | # Optional ENV vars 29 | # ----------------- 30 | # M2_HOME - location of maven2's installed home dir 31 | # MAVEN_OPTS - parameters passed to the Java VM when running Maven 32 | # e.g. to debug Maven itself, use 33 | # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 34 | # MAVEN_SKIP_RC - flag to disable loading of mavenrc files 35 | # ---------------------------------------------------------------------------- 36 | 37 | if [ -z "$MAVEN_SKIP_RC" ] ; then 38 | 39 | if [ -f /etc/mavenrc ] ; then 40 | . /etc/mavenrc 41 | fi 42 | 43 | if [ -f "$HOME/.mavenrc" ] ; then 44 | . "$HOME/.mavenrc" 45 | fi 46 | 47 | fi 48 | 49 | # OS specific support. $var _must_ be set to either true or false. 50 | cygwin=false; 51 | darwin=false; 52 | mingw=false 53 | case "`uname`" in 54 | CYGWIN*) cygwin=true ;; 55 | MINGW*) mingw=true;; 56 | Darwin*) darwin=true 57 | # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home 58 | # See https://developer.apple.com/library/mac/qa/qa1170/_index.html 59 | if [ -z "$JAVA_HOME" ]; then 60 | if [ -x "/usr/libexec/java_home" ]; then 61 | export JAVA_HOME="`/usr/libexec/java_home`" 62 | else 63 | export JAVA_HOME="/Library/Java/Home" 64 | fi 65 | fi 66 | ;; 67 | esac 68 | 69 | if [ -z "$JAVA_HOME" ] ; then 70 | if [ -r /etc/gentoo-release ] ; then 71 | JAVA_HOME=`java-config --jre-home` 72 | fi 73 | fi 74 | 75 | if [ -z "$M2_HOME" ] ; then 76 | ## resolve links - $0 may be a link to maven's home 77 | PRG="$0" 78 | 79 | # need this for relative symlinks 80 | while [ -h "$PRG" ] ; do 81 | ls=`ls -ld "$PRG"` 82 | link=`expr "$ls" : '.*-> \(.*\)$'` 83 | if expr "$link" : '/.*' > /dev/null; then 84 | PRG="$link" 85 | else 86 | PRG="`dirname "$PRG"`/$link" 87 | fi 88 | done 89 | 90 | saveddir=`pwd` 91 | 92 | M2_HOME=`dirname "$PRG"`/.. 93 | 94 | # make it fully qualified 95 | M2_HOME=`cd "$M2_HOME" && pwd` 96 | 97 | cd "$saveddir" 98 | # echo Using m2 at $M2_HOME 99 | fi 100 | 101 | # For Cygwin, ensure paths are in UNIX format before anything is touched 102 | if $cygwin ; then 103 | [ -n "$M2_HOME" ] && 104 | M2_HOME=`cygpath --unix "$M2_HOME"` 105 | [ -n "$JAVA_HOME" ] && 106 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 107 | [ -n "$CLASSPATH" ] && 108 | CLASSPATH=`cygpath --path --unix "$CLASSPATH"` 109 | fi 110 | 111 | # For Migwn, ensure paths are in UNIX format before anything is touched 112 | if $mingw ; then 113 | [ -n "$M2_HOME" ] && 114 | M2_HOME="`(cd "$M2_HOME"; pwd)`" 115 | [ -n "$JAVA_HOME" ] && 116 | JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" 117 | # TODO classpath? 118 | fi 119 | 120 | if [ -z "$JAVA_HOME" ]; then 121 | javaExecutable="`which javac`" 122 | if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then 123 | # readlink(1) is not available as standard on Solaris 10. 124 | readLink=`which readlink` 125 | if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then 126 | if $darwin ; then 127 | javaHome="`dirname \"$javaExecutable\"`" 128 | javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" 129 | else 130 | javaExecutable="`readlink -f \"$javaExecutable\"`" 131 | fi 132 | javaHome="`dirname \"$javaExecutable\"`" 133 | javaHome=`expr "$javaHome" : '\(.*\)/bin'` 134 | JAVA_HOME="$javaHome" 135 | export JAVA_HOME 136 | fi 137 | fi 138 | fi 139 | 140 | if [ -z "$JAVACMD" ] ; then 141 | if [ -n "$JAVA_HOME" ] ; then 142 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 143 | # IBM's JDK on AIX uses strange locations for the executables 144 | JAVACMD="$JAVA_HOME/jre/sh/java" 145 | else 146 | JAVACMD="$JAVA_HOME/bin/java" 147 | fi 148 | else 149 | JAVACMD="`which java`" 150 | fi 151 | fi 152 | 153 | if [ ! -x "$JAVACMD" ] ; then 154 | echo "Error: JAVA_HOME is not defined correctly." >&2 155 | echo " We cannot execute $JAVACMD" >&2 156 | exit 1 157 | fi 158 | 159 | if [ -z "$JAVA_HOME" ] ; then 160 | echo "Warning: JAVA_HOME environment variable is not set." 161 | fi 162 | 163 | CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher 164 | 165 | # traverses directory structure from process work directory to filesystem root 166 | # first directory with .mvn subdirectory is considered project base directory 167 | find_maven_basedir() { 168 | 169 | if [ -z "$1" ] 170 | then 171 | echo "Path not specified to find_maven_basedir" 172 | return 1 173 | fi 174 | 175 | basedir="$1" 176 | wdir="$1" 177 | while [ "$wdir" != '/' ] ; do 178 | if [ -d "$wdir"/.mvn ] ; then 179 | basedir=$wdir 180 | break 181 | fi 182 | # workaround for JBEAP-8937 (on Solaris 10/Sparc) 183 | if [ -d "${wdir}" ]; then 184 | wdir=`cd "$wdir/.."; pwd` 185 | fi 186 | # end of workaround 187 | done 188 | echo "${basedir}" 189 | } 190 | 191 | # concatenates all lines of a file 192 | concat_lines() { 193 | if [ -f "$1" ]; then 194 | echo "$(tr -s '\n' ' ' < "$1")" 195 | fi 196 | } 197 | 198 | BASE_DIR=`find_maven_basedir "$(pwd)"` 199 | if [ -z "$BASE_DIR" ]; then 200 | exit 1; 201 | fi 202 | 203 | export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} 204 | echo $MAVEN_PROJECTBASEDIR 205 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" 206 | 207 | # For Cygwin, switch paths to Windows format before running java 208 | if $cygwin; then 209 | [ -n "$M2_HOME" ] && 210 | M2_HOME=`cygpath --path --windows "$M2_HOME"` 211 | [ -n "$JAVA_HOME" ] && 212 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` 213 | [ -n "$CLASSPATH" ] && 214 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"` 215 | [ -n "$MAVEN_PROJECTBASEDIR" ] && 216 | MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` 217 | fi 218 | 219 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 220 | 221 | exec "$JAVACMD" \ 222 | $MAVEN_OPTS \ 223 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ 224 | "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ 225 | ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" 226 | -------------------------------------------------------------------------------- /springboot2-jpa-crud-example/mvnw.cmd: -------------------------------------------------------------------------------- 1 | @REM ---------------------------------------------------------------------------- 2 | @REM Licensed to the Apache Software Foundation (ASF) under one 3 | @REM or more contributor license agreements. See the NOTICE file 4 | @REM distributed with this work for additional information 5 | @REM regarding copyright ownership. The ASF licenses this file 6 | @REM to you under the Apache License, Version 2.0 (the 7 | @REM "License"); you may not use this file except in compliance 8 | @REM with the License. You may obtain a copy of the License at 9 | @REM 10 | @REM http://www.apache.org/licenses/LICENSE-2.0 11 | @REM 12 | @REM Unless required by applicable law or agreed to in writing, 13 | @REM software distributed under the License is distributed on an 14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | @REM KIND, either express or implied. See the License for the 16 | @REM specific language governing permissions and limitations 17 | @REM under the License. 18 | @REM ---------------------------------------------------------------------------- 19 | 20 | @REM ---------------------------------------------------------------------------- 21 | @REM Maven2 Start Up Batch script 22 | @REM 23 | @REM Required ENV vars: 24 | @REM JAVA_HOME - location of a JDK home dir 25 | @REM 26 | @REM Optional ENV vars 27 | @REM M2_HOME - location of maven2's installed home dir 28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands 29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending 30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven 31 | @REM e.g. to debug Maven itself, use 32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files 34 | @REM ---------------------------------------------------------------------------- 35 | 36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' 37 | @echo off 38 | @REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' 39 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% 40 | 41 | @REM set %HOME% to equivalent of $HOME 42 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") 43 | 44 | @REM Execute a user defined script before this one 45 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre 46 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending 47 | if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" 48 | if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" 49 | :skipRcPre 50 | 51 | @setlocal 52 | 53 | set ERROR_CODE=0 54 | 55 | @REM To isolate internal variables from possible post scripts, we use another setlocal 56 | @setlocal 57 | 58 | @REM ==== START VALIDATION ==== 59 | if not "%JAVA_HOME%" == "" goto OkJHome 60 | 61 | echo. 62 | echo Error: JAVA_HOME not found in your environment. >&2 63 | echo Please set the JAVA_HOME variable in your environment to match the >&2 64 | echo location of your Java installation. >&2 65 | echo. 66 | goto error 67 | 68 | :OkJHome 69 | if exist "%JAVA_HOME%\bin\java.exe" goto init 70 | 71 | echo. 72 | echo Error: JAVA_HOME is set to an invalid directory. >&2 73 | echo JAVA_HOME = "%JAVA_HOME%" >&2 74 | echo Please set the JAVA_HOME variable in your environment to match the >&2 75 | echo location of your Java installation. >&2 76 | echo. 77 | goto error 78 | 79 | @REM ==== END VALIDATION ==== 80 | 81 | :init 82 | 83 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn". 84 | @REM Fallback to current working directory if not found. 85 | 86 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% 87 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir 88 | 89 | set EXEC_DIR=%CD% 90 | set WDIR=%EXEC_DIR% 91 | :findBaseDir 92 | IF EXIST "%WDIR%"\.mvn goto baseDirFound 93 | cd .. 94 | IF "%WDIR%"=="%CD%" goto baseDirNotFound 95 | set WDIR=%CD% 96 | goto findBaseDir 97 | 98 | :baseDirFound 99 | set MAVEN_PROJECTBASEDIR=%WDIR% 100 | cd "%EXEC_DIR%" 101 | goto endDetectBaseDir 102 | 103 | :baseDirNotFound 104 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR% 105 | cd "%EXEC_DIR%" 106 | 107 | :endDetectBaseDir 108 | 109 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig 110 | 111 | @setlocal EnableExtensions EnableDelayedExpansion 112 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a 113 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% 114 | 115 | :endReadAdditionalConfig 116 | 117 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" 118 | 119 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" 120 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 121 | 122 | %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* 123 | if ERRORLEVEL 1 goto error 124 | goto end 125 | 126 | :error 127 | set ERROR_CODE=1 128 | 129 | :end 130 | @endlocal & set ERROR_CODE=%ERROR_CODE% 131 | 132 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost 133 | @REM check for post script, once with legacy .bat ending and once with .cmd ending 134 | if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" 135 | if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" 136 | :skipRcPost 137 | 138 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' 139 | if "%MAVEN_BATCH_PAUSE%" == "on" pause 140 | 141 | if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% 142 | 143 | exit /B %ERROR_CODE% 144 | -------------------------------------------------------------------------------- /springboot2-jpa-crud-example/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | net.guides.springboot2 8 | springboot2-jpa-crud-example 9 | 0.0.1-SNAPSHOT 10 | jar 11 | 12 | springboot2-jpa-crud-example 13 | Demo project for Spring Boot 14 | 15 | 16 | org.springframework.boot 17 | spring-boot-starter-parent 18 | 3.0.4 19 | 20 | 21 | 22 | 23 | UTF-8 24 | UTF-8 25 | 17 26 | 27 | 28 | 29 | 30 | org.springframework.boot 31 | spring-boot-starter-data-jpa 32 | 33 | 34 | org.springframework.boot 35 | spring-boot-starter-web 36 | 37 | 38 | 39 | org.springframework.boot 40 | spring-boot-starter-actuator 41 | 42 | 43 | 44 | org.springframework.boot 45 | spring-boot-devtools 46 | runtime 47 | 48 | 49 | com.h2database 50 | h2 51 | runtime 52 | 53 | 54 | org.springframework.boot 55 | spring-boot-starter-test 56 | test 57 | 58 | 59 | 60 | 61 | 62 | 63 | org.springframework.boot 64 | spring-boot-maven-plugin 65 | 66 | 67 | 68 | 69 | 70 | 71 | -------------------------------------------------------------------------------- /springboot2-jpa-crud-example/src/main/java/net/guides/springboot2/springboot2jpacrudexample/Application.java: -------------------------------------------------------------------------------- 1 | package net.guides.springboot2.springboot2jpacrudexample; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class Application { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(Application.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /springboot2-jpa-crud-example/src/main/java/net/guides/springboot2/springboot2jpacrudexample/controller/EmployeeController.java: -------------------------------------------------------------------------------- 1 | package net.guides.springboot2.springboot2jpacrudexample.controller; 2 | 3 | import java.util.HashMap; 4 | 5 | import java.util.List; 6 | import java.util.Map; 7 | 8 | import jakarta.validation.Valid; 9 | 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.http.ResponseEntity; 12 | import org.springframework.web.bind.annotation.CrossOrigin; 13 | import org.springframework.web.bind.annotation.DeleteMapping; 14 | import org.springframework.web.bind.annotation.GetMapping; 15 | import org.springframework.web.bind.annotation.PathVariable; 16 | import org.springframework.web.bind.annotation.PostMapping; 17 | import org.springframework.web.bind.annotation.PutMapping; 18 | import org.springframework.web.bind.annotation.RequestBody; 19 | import org.springframework.web.bind.annotation.RequestMapping; 20 | import org.springframework.web.bind.annotation.RestController; 21 | 22 | import net.guides.springboot2.springboot2jpacrudexample.exception.ResourceNotFoundException; 23 | import net.guides.springboot2.springboot2jpacrudexample.model.Employee; 24 | import net.guides.springboot2.springboot2jpacrudexample.repository.EmployeeRepository; 25 | 26 | @CrossOrigin(origins = "http://localhost:4200") 27 | @RestController 28 | @RequestMapping("/api/v1") 29 | public class EmployeeController { 30 | @Autowired 31 | private EmployeeRepository employeeRepository; 32 | 33 | @GetMapping("/employees") 34 | public List getAllEmployees() { 35 | return employeeRepository.findAll(); 36 | } 37 | 38 | @GetMapping("/employees/{id}") 39 | public ResponseEntity getEmployeeById(@PathVariable(value = "id") Long employeeId) 40 | throws ResourceNotFoundException { 41 | Employee employee = employeeRepository.findById(employeeId) 42 | .orElseThrow(() -> new ResourceNotFoundException("Employee not found for this id :: " + employeeId)); 43 | return ResponseEntity.ok().body(employee); 44 | } 45 | 46 | @PostMapping("/employees") 47 | public Employee createEmployee(@Valid @RequestBody Employee employee) { 48 | return employeeRepository.save(employee); 49 | } 50 | 51 | @PutMapping("/employees/{id}") 52 | public ResponseEntity updateEmployee(@PathVariable(value = "id") Long employeeId, 53 | @Valid @RequestBody Employee employeeDetails) throws ResourceNotFoundException { 54 | Employee employee = employeeRepository.findById(employeeId) 55 | .orElseThrow(() -> new ResourceNotFoundException("Employee not found for this id :: " + employeeId)); 56 | 57 | employee.setEmailId(employeeDetails.getEmailId()); 58 | employee.setLastName(employeeDetails.getLastName()); 59 | employee.setFirstName(employeeDetails.getFirstName()); 60 | final Employee updatedEmployee = employeeRepository.save(employee); 61 | return ResponseEntity.ok(updatedEmployee); 62 | } 63 | 64 | @DeleteMapping("/employees/{id}") 65 | public Map deleteEmployee(@PathVariable(value = "id") Long employeeId) 66 | throws ResourceNotFoundException { 67 | Employee employee = employeeRepository.findById(employeeId) 68 | .orElseThrow(() -> new ResourceNotFoundException("Employee not found for this id :: " + employeeId)); 69 | 70 | employeeRepository.delete(employee); 71 | Map response = new HashMap<>(); 72 | response.put("deleted", Boolean.TRUE); 73 | return response; 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /springboot2-jpa-crud-example/src/main/java/net/guides/springboot2/springboot2jpacrudexample/exception/ErrorDetails.java: -------------------------------------------------------------------------------- 1 | package net.guides.springboot2.springboot2jpacrudexample.exception; 2 | 3 | import java.util.Date; 4 | 5 | public class ErrorDetails { 6 | private Date timestamp; 7 | private String message; 8 | private String details; 9 | 10 | public ErrorDetails(Date timestamp, String message, String details) { 11 | super(); 12 | this.timestamp = timestamp; 13 | this.message = message; 14 | this.details = details; 15 | } 16 | 17 | public Date getTimestamp() { 18 | return timestamp; 19 | } 20 | 21 | public String getMessage() { 22 | return message; 23 | } 24 | 25 | public String getDetails() { 26 | return details; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /springboot2-jpa-crud-example/src/main/java/net/guides/springboot2/springboot2jpacrudexample/exception/GlobalExceptionHandler.java: -------------------------------------------------------------------------------- 1 | package net.guides.springboot2.springboot2jpacrudexample.exception; 2 | 3 | import java.util.Date; 4 | 5 | import org.springframework.http.HttpStatus; 6 | import org.springframework.http.ResponseEntity; 7 | import org.springframework.web.bind.annotation.ControllerAdvice; 8 | import org.springframework.web.bind.annotation.ExceptionHandler; 9 | import org.springframework.web.context.request.WebRequest; 10 | import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler; 11 | 12 | @ControllerAdvice 13 | public class GlobalExceptionHandler extends ResponseEntityExceptionHandler { 14 | @ExceptionHandler(ResourceNotFoundException.class) 15 | public ResponseEntity resourceNotFoundException(ResourceNotFoundException ex, WebRequest request) { 16 | ErrorDetails errorDetails = new ErrorDetails(new Date(), ex.getMessage(), request.getDescription(false)); 17 | return new ResponseEntity<>(errorDetails, HttpStatus.NOT_FOUND); 18 | } 19 | 20 | @ExceptionHandler(Exception.class) 21 | public ResponseEntity globleExcpetionHandler(Exception ex, WebRequest request) { 22 | ErrorDetails errorDetails = new ErrorDetails(new Date(), ex.getMessage(), request.getDescription(false)); 23 | return new ResponseEntity<>(errorDetails, HttpStatus.INTERNAL_SERVER_ERROR); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /springboot2-jpa-crud-example/src/main/java/net/guides/springboot2/springboot2jpacrudexample/exception/ResourceNotFoundException.java: -------------------------------------------------------------------------------- 1 | package net.guides.springboot2.springboot2jpacrudexample.exception; 2 | 3 | import org.springframework.http.HttpStatus; 4 | import org.springframework.web.bind.annotation.ResponseStatus; 5 | 6 | @ResponseStatus(value = HttpStatus.NOT_FOUND) 7 | public class ResourceNotFoundException extends Exception{ 8 | 9 | private static final long serialVersionUID = 1L; 10 | 11 | public ResourceNotFoundException(String message){ 12 | super(message); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /springboot2-jpa-crud-example/src/main/java/net/guides/springboot2/springboot2jpacrudexample/model/Employee.java: -------------------------------------------------------------------------------- 1 | package net.guides.springboot2.springboot2jpacrudexample.model; 2 | 3 | import jakarta.persistence.*; 4 | 5 | @Entity 6 | @Table(name = "employees") 7 | public class Employee { 8 | 9 | private long id; 10 | private String firstName; 11 | private String lastName; 12 | private String emailId; 13 | 14 | public Employee() { 15 | 16 | } 17 | 18 | public Employee(String firstName, String lastName, String emailId) { 19 | this.firstName = firstName; 20 | this.lastName = lastName; 21 | this.emailId = emailId; 22 | } 23 | 24 | @Id 25 | @GeneratedValue(strategy = GenerationType.AUTO) 26 | public long getId() { 27 | return id; 28 | } 29 | public void setId(long id) { 30 | this.id = id; 31 | } 32 | 33 | @Column(name = "first_name", nullable = false) 34 | public String getFirstName() { 35 | return firstName; 36 | } 37 | public void setFirstName(String firstName) { 38 | this.firstName = firstName; 39 | } 40 | 41 | @Column(name = "last_name", nullable = false) 42 | public String getLastName() { 43 | return lastName; 44 | } 45 | public void setLastName(String lastName) { 46 | this.lastName = lastName; 47 | } 48 | 49 | @Column(name = "email_address", nullable = false) 50 | public String getEmailId() { 51 | return emailId; 52 | } 53 | public void setEmailId(String emailId) { 54 | this.emailId = emailId; 55 | } 56 | 57 | @Override 58 | public String toString() { 59 | return "Employee [id=" + id + ", firstName=" + firstName + ", lastName=" + lastName + ", emailId=" + emailId 60 | + "]"; 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /springboot2-jpa-crud-example/src/main/java/net/guides/springboot2/springboot2jpacrudexample/repository/EmployeeRepository.java: -------------------------------------------------------------------------------- 1 | package net.guides.springboot2.springboot2jpacrudexample.repository; 2 | 3 | import org.springframework.data.jpa.repository.JpaRepository; 4 | import org.springframework.stereotype.Repository; 5 | 6 | import net.guides.springboot2.springboot2jpacrudexample.model.Employee; 7 | 8 | @Repository 9 | public interface EmployeeRepository extends JpaRepository{ 10 | 11 | } 12 | -------------------------------------------------------------------------------- /springboot2-jpa-crud-example/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | ## Spring DATASOURCE (DataSourceAutoConfiguration & DataSourceProperties) 2 | #spring.datasource.url = jdbc:mysql://localhost:3306/users_database?useSSL=false 3 | #spring.datasource.username = root 4 | #spring.datasource.password = root 5 | 6 | 7 | ## Hibernate Properties 8 | # The SQL dialect makes Hibernate generate better SQL for the chosen database 9 | #spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5InnoDBDialect 10 | 11 | # Hibernate ddl auto (create, create-drop, validate, update) 12 | #spring.jpa.hibernate.ddl-auto = update 13 | 14 | info.app.name=Spring Boot - RestTemplate CRUD Rest Client Example 15 | info.app.description=Spring Boot - RestTemplate CRUD Rest Client Example 16 | info.app.version=1.0.0 17 | 18 | server.servlet.context-path=/springboot-crud-rest -------------------------------------------------------------------------------- /springboot2-jpa-crud-example/src/test/java/net/guides/springboot2/springboot2jpacrudexample/ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package net.guides.springboot2.springboot2jpacrudexample; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class ApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /springboot2-jpa-crud-example/src/test/java/net/guides/springboot2/springboot2jpacrudexample/EmployeeControllerIntegrationTest.java: -------------------------------------------------------------------------------- 1 | package net.guides.springboot2.springboot2jpacrudexample; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | import static org.junit.Assert.assertNotNull; 5 | 6 | import org.junit.Test; 7 | import org.junit.runner.RunWith; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.boot.test.context.SpringBootTest; 10 | import org.springframework.boot.test.web.client.TestRestTemplate; 11 | import org.springframework.boot.web.server.LocalServerPort; 12 | import org.springframework.http.HttpEntity; 13 | import org.springframework.http.HttpHeaders; 14 | import org.springframework.http.HttpMethod; 15 | import org.springframework.http.HttpStatus; 16 | import org.springframework.http.ResponseEntity; 17 | import org.springframework.test.context.junit4.SpringRunner; 18 | import org.springframework.web.client.HttpClientErrorException; 19 | 20 | import net.guides.springboot2.springboot2jpacrudexample.model.Employee; 21 | 22 | @RunWith(SpringRunner.class) 23 | @SpringBootTest(classes = Application.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) 24 | public class EmployeeControllerIntegrationTest { 25 | @Autowired 26 | private TestRestTemplate restTemplate; 27 | 28 | @LocalServerPort 29 | private int port; 30 | 31 | private String getRootUrl() { 32 | return "http://localhost:" + port; 33 | } 34 | 35 | @Test 36 | public void contextLoads() { 37 | 38 | } 39 | 40 | @Test 41 | public void testGetAllEmployees() { 42 | HttpHeaders headers = new HttpHeaders(); 43 | HttpEntity entity = new HttpEntity(null, headers); 44 | 45 | ResponseEntity response = restTemplate.exchange(getRootUrl() + "/employees", 46 | HttpMethod.GET, entity, String.class); 47 | 48 | assertNotNull(response.getBody()); 49 | } 50 | 51 | @Test 52 | public void testGetEmployeeById() { 53 | Employee employee = restTemplate.getForObject(getRootUrl() + "/employees/1", Employee.class); 54 | System.out.println(employee.getFirstName()); 55 | assertNotNull(employee); 56 | } 57 | 58 | @Test 59 | public void testCreateEmployee() { 60 | Employee employee = new Employee(); 61 | employee.setEmailId("admin@gmail.com"); 62 | employee.setFirstName("admin"); 63 | employee.setLastName("admin"); 64 | 65 | ResponseEntity postResponse = restTemplate.postForEntity(getRootUrl() + "/employees", employee, Employee.class); 66 | assertNotNull(postResponse); 67 | assertNotNull(postResponse.getBody()); 68 | } 69 | 70 | @Test 71 | public void testUpdateEmployee() { 72 | int id = 1; 73 | Employee employee = restTemplate.getForObject(getRootUrl() + "/employees/" + id, Employee.class); 74 | employee.setFirstName("admin1"); 75 | employee.setLastName("admin2"); 76 | 77 | restTemplate.put(getRootUrl() + "/employees/" + id, employee); 78 | 79 | Employee updatedEmployee = restTemplate.getForObject(getRootUrl() + "/employees/" + id, Employee.class); 80 | assertNotNull(updatedEmployee); 81 | } 82 | 83 | @Test 84 | public void testDeleteEmployee() { 85 | int id = 2; 86 | Employee employee = restTemplate.getForObject(getRootUrl() + "/employees/" + id, Employee.class); 87 | assertNotNull(employee); 88 | 89 | restTemplate.delete(getRootUrl() + "/employees/" + id); 90 | 91 | try { 92 | employee = restTemplate.getForObject(getRootUrl() + "/employees/" + id, Employee.class); 93 | } catch (final HttpClientErrorException e) { 94 | assertEquals(e.getStatusCode(), HttpStatus.NOT_FOUND); 95 | } 96 | } 97 | } 98 | --------------------------------------------------------------------------------