All Projects → phantasmicmeans → spring-boot-restful-api-example

phantasmicmeans / spring-boot-restful-api-example

Licence: MIT license
REST API with Spring Boot ,Swagger 2, Data JPA, hibernate, Mysql, One to Many , Many to One Bidirectional mapping

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to spring-boot-restful-api-example

SpringMVCgbook
springMVC Hibernate (ssh) 留言板管理系统
Stars: ✭ 18 (-45.45%)
Mutual labels:  hibernate
assembler
Functional, type-safe, stateless reactive Java API for efficient implementation of the API Composition Pattern for querying/merging data from multiple datasources/services, with a specific focus on solving the N + 1 query problem
Stars: ✭ 102 (+209.09%)
Mutual labels:  hibernate
Desktop-Applications-JavaFX
JavaFX Open Source Projects
Stars: ✭ 69 (+109.09%)
Mutual labels:  hibernate
employeeManager
自己尝试写的一个简单的考勤管理系统,包含管理成员信息以及成员考勤,管理员审批的功能,采用SpringMVC+Hibernate4+Spring搭建
Stars: ✭ 40 (+21.21%)
Mutual labels:  hibernate
grails-audit-logging-plugin
The Grails Audit Logging Plugin
Stars: ✭ 49 (+48.48%)
Mutual labels:  hibernate
spring-javafx-material-design-admin
Aplicação desktop para Gerenciamento de estoque e vendas com Spring Boot, JavaFX e Material Design
Stars: ✭ 56 (+69.7%)
Mutual labels:  hibernate
authority-manage-system
使用SpringBoot/WebFlux+Shiro+JPA+Java/Scala,实现的基于数据库细粒度动态权限管理系统
Stars: ✭ 66 (+100%)
Mutual labels:  springdata-jpa
spring-boot-java-swing-reservations
The project aims to present how to connect Spring Boot 2 and Java Swing GUI widget toolkit. All application dependencies are provided by Docker Compose. There are also static code analysis tools like FindBugs and Checkstyle.
Stars: ✭ 86 (+160.61%)
Mutual labels:  hibernate
hibernate-springcache
Hibernate cache implementation that backs to the Spring Cache abstraction
Stars: ✭ 19 (-42.42%)
Mutual labels:  hibernate
multi-tenant
Spring boot + Hibernate + Postgresql的多租户实现Demo
Stars: ✭ 110 (+233.33%)
Mutual labels:  hibernate
acrobot
A simple acronym bot for Google Chat
Stars: ✭ 23 (-30.3%)
Mutual labels:  hibernate
springboot-crud-restful-webservices
Spring Boot, MySQL, JPA, Hibernate Restful CRUD API Tutorial
Stars: ✭ 41 (+24.24%)
Mutual labels:  hibernate
online-shopping
This is an online shopping project using Spring Boot,Spring web-flow, Spring Rest Services and Hibernate. In this project we also used Spring Security with java and annotation configuration
Stars: ✭ 34 (+3.03%)
Mutual labels:  hibernate
spring-boot-shop-sample
My first web application using Spring Boot framework.
Stars: ✭ 66 (+100%)
Mutual labels:  hibernate
hibernate
No description or website provided.
Stars: ✭ 13 (-60.61%)
Mutual labels:  hibernate
spring-discord-bot
Discord all-purpose bot, made using Spring Boot, JPA, Hibernate, REST, HikariCP. Written for fun, do not take this serious.
Stars: ✭ 26 (-21.21%)
Mutual labels:  hibernate
spring-filter
Painless filtering library for JPA entities and MongoDB collections. Smoothly integrates with Spring APIs.
Stars: ✭ 123 (+272.73%)
Mutual labels:  hibernate
springboot-schema-per-tenant
Seed for achieving multi-tenancy (single pooled schema-per-tenant) using SpringBoot and Hibernate
Stars: ✭ 75 (+127.27%)
Mutual labels:  hibernate
TendereteOnline
A Java EE web application of an Online Shop developed with Hibernate + Spring + Bootstrap + jQuery
Stars: ✭ 19 (-42.42%)
Mutual labels:  hibernate
hibernate-table-relationship
在 Hibernate 中如何配置多表关系映射,包括:一对一、一对多和多对多。
Stars: ✭ 15 (-54.55%)
Mutual labels:  one-to-many

HitCount

Spring Boot RESTful API - JPA Hibernate MySQL Example

by S.M.Lee(phantasmicmeans)

RESTful API using Spring Boot, Swagger2, JPA hibernate and Mysql, One to Many, Many to One bidirectional mapping

 

Relation

image

Bidirectional Mapping

  • Project - Problem (One-To-Many)

  • Problem - Project (Many-To-One)

  • Problem - SubProblem (One-To-Many)

  • SubProblem - Problem (Many-To-One)

 

Before we go, Check the domain class

1. Problem.java(part of)

@OneToMany(mappedBy = "project", cascade = CascadeType.REMOVE, fetch = FetchType.LAZY, orphanRemoval = true)
private Set <Problem> problems = new HashSet<>();
/* Project <-> Problem One to Many bidirectional */

2. Problem.java(part of)

@ManyToOne(cascade = CascadeType.REMOVE)
@JoinColumn(name = "code", referencedColumnName = "code", nullable = false)
private Project project; 
/* Problem <-> Project  Many to One bidirectional */

@OneToMany(mappedBy = "problem", cascade = CascadeType.ALL, fetch = FetchType.LAZY, orphanRemoval = true)
private Set<subProblem> subProblems = new HashSet<>();
//Problem <-> SubProblem  One to Many bidirectional

3. SubProblem.java(part of)

@ManyToOne(cascade = CascadeType.REMOVE)
@JoinColumn(name = "pro_idx", referencedColumnName = "idx", nullable = false)
private Problem problem; 
/* Problem <-> Project Many to One bidirectional */

 

RESTful API Server

  1. API Description for Project

METHOD PATH DESCRIPTION
GET /api/project/{code} get Project-Problem-SubProblem with code
POST /api/project save Project (code will generate by constructor)
DELETE /api/project/{code} delete Project with code
PUT /api/project/{code} update Project with code

  2. API Description for Problem & SubProblem

METHOD PATH DESCRIPTION
GET /api/problem/{code} get all Problem-Subproblem with code
POST /api/problem/{code} save Problem with code
DELETE /api/problem/{code}/all delete all Problem-Subproblem with code
POST /api/subproblem save Subproblem

 

Curl

  1. Curl for Project

  1. Get a Project with code
curl -X GET http://localhost:8080/problem/0gn547 
  1. Save a Project with code
curl -d '{"title":"first project"}' -H "Content-Type: application/json" -X POST http://localhost:8080/project
  1. Delete a Project with code
curl -X DELETE http://localhost:8001/project/0gn547
  1. Update a Project with code
curl -X PUT -H "Content-Type: application/json; charset=utf-8" -d '{"title":"first-project-renewal"}' http://localhost:8080/project/hx6029

 

2. Curl for Problem & SubProblem  

  1. Get a Problem with code
curl -X GET http://localhost:8001/problem/0gn547 
  1. Save a Problem with code
curl -d '{"title":"first problem"}' -H "Content-Type: application/json" -X POST http://localhost:8080/problem/hx6029
  1. Delete a Problem-SubProblem with code
curl -X DELETE http://localhost:8001/problem/hx6029/all 
  1. Save a SubProblem
curl -d '{"content":"first-subproblem","pro_idx":1}' -H "Content-Type: application/json" -X POST http://localhost:8080/subproblem

 

Running the project with MySQL

append this at the end of application.yml  

spring:
    application:
      name: project-api
       
## Hibernate Properties
# The SQL dialect makes Hibernate generate better SQL for the chosen database
    jpa: 
      properties:
        hibernate:
          dialect: org.hibernate.dialect.MySQL5InnoDBDialect
      hibernate:
        ddl-auto: update
        # Hibernate ddl auto (create, create-drop, validate, update)
      
    datasource:
      url: jdbc:mysql://{YOUR_MSQL_SERVER}:3306/{DATABASE NAME}?useSSL=false
      username: {YOUR_MYSQL_ID}
      password: {YOUR_MYSQL{PASSWORD}
      driver-class-name: com.mysql.jdbc.Driver
      hikari:
        maximum-pool-size: 2

 

Swagger

You can use the Swagger API Documentation at http://{Your_Server}:{Port}/swagger-ui.html

image

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].