Search

μƒν’ˆ 관리 BackEnd (SpringBoot)

μƒν’ˆ 관리 REST API μ„œλ²„ κ΅¬ν˜„

1.
μƒν’ˆ ν…Œμ΄λΈ” μ •μ˜
2.
Spring Boot REST API κ΅¬ν˜„
3.
API λͺ…μ„Έμ„œ μžλ™ 생성 - OpenAPI(Swagger)
4.
API ν…ŒμŠ€νŠΈ

μƒν’ˆ ν…Œμ΄λΈ” μ •μ˜

DROP TABLE IF EXISTS `products`; CREATE TABLE `products` ( `no` BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY COMMENT 'PK', `id` VARCHAR(64) NOT NULL COMMENT 'UK', `title` VARCHAR(100) NOT NULL COMMENT 'μƒν’ˆλͺ…', `content` TEXT NULL COMMENT 'μ„€λͺ…', `likes` BIGINT NULL DEFAULT 0 COMMENT 'μ’‹μ•„μš”', `img` TEXT NULL COMMENT 'μ΄λ―Έμ§€κ²½λ‘œ', `created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'λ“±λ‘μΌμž', `updated_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'μˆ˜μ •μΌμž' );
SQL
볡사

Spring Boot REST API κ΅¬ν˜„

μš”μ²­ λ©”μ†Œλ“œ
μš”μ²­ 경둜
ν•­λͺ©
λΉ„κ³ 
GET
/products
μƒν’ˆ λͺ©λ‘
GET
/products/{id}
μƒν’ˆ 쑰회
POST
/products
μƒν’ˆ 등둝
PUT
/products
μƒν’ˆ μˆ˜μ •
DELETE
/products/{id}
μƒν’ˆ μ‚­μ œ
β€’
domain
β—¦
Product.java
β€’
Mapper
β—¦
ProductMapper.xml
β—¦
BaseMapper.java
β—¦
ProductMapper.java
β€’
Service
β—¦
BaseService.java
β—¦
ProductService.java
β—¦
ProductServiceImpl.java
β€’
Controller
β—¦
@CrossOrigin("*")
β—¦
@RestController
β–ͺ
sp-crud

API λͺ…μ„Έμ„œ μžλ™ 생성 - OpenAPI(Swagger)

SpringDoc OpenAPI Starter WebMVC UI

// Springdoc openapi implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.7.0'
SQL
볡사

build.gradle

plugins { id 'java' id 'war' id 'org.springframework.boot' version '3.4.1' id 'io.spring.dependency-management' version '1.1.6' } group = 'com.aloha' version = '0.0.1-SNAPSHOT' java { toolchain { languageVersion = JavaLanguageVersion.of(17) } } configurations { compileOnly { extendsFrom annotationProcessor } } repositories { mavenCentral() } dependencies { implementation 'org.springframework.boot:spring-boot-starter-web' implementation 'org.mybatis.spring.boot:mybatis-spring-boot-starter:3.0.4' compileOnly 'org.projectlombok:lombok' developmentOnly 'org.springframework.boot:spring-boot-devtools' runtimeOnly 'com.mysql:mysql-connector-j' annotationProcessor 'org.projectlombok:lombok' providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat' testImplementation 'org.springframework.boot:spring-boot-starter-test' testImplementation 'org.mybatis.spring.boot:mybatis-spring-boot-starter-test:3.0.4' testRuntimeOnly 'org.junit.platform:junit-platform-launcher' // Springdoc openapi implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.7.0' } tasks.named('test') { useJUnitPlatform() }
SQL
볡사

SwaggerConfig.java

import org.springdoc.core.models.GroupedOpenApi; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import io.swagger.v3.oas.models.OpenAPI; import io.swagger.v3.oas.models.info.Info; @Configuration public class SwaggerConfig { @Bean public GroupedOpenApi publicApi() { return GroupedOpenApi.builder() .group("aloha") // κ·Έλ£Ήλͺ… μ„€μ • .pathsToMatch("/**") // 경둜 μ„€μ • .build(); } @Bean public OpenAPI springShopOpenAPI() { return new OpenAPI() .info(new Info().title("μƒν’ˆ 관리 Proejct API") .description("μƒν’ˆ 관리 ν”„λ‘œμ νŠΈ API μž…λ‹ˆλ‹€.") .version("v0.0.1")); } }
Java
볡사

기본 경둜