Compare commits
2 Commits
feature/h2
...
feature/sw
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4afd28eb4a | ||
|
|
11f073de61 |
@@ -23,6 +23,8 @@ dependencies {
|
||||
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
|
||||
implementation 'org.springframework.boot:spring-boot-starter-freemarker'
|
||||
implementation 'org.springframework.boot:spring-boot-starter-web'
|
||||
implementation 'io.springfox:springfox-swagger2:2.6.1'
|
||||
implementation 'io.springfox:springfox-swagger-ui:2.6.1'
|
||||
compileOnly 'org.projectlombok:lombok'
|
||||
runtimeOnly 'com.h2database:h2'
|
||||
runtimeOnly 'mysql:mysql-connector-java'
|
||||
|
||||
30
src/main/java/com/rest/api/config/SwaggerConfiguration.java
Normal file
30
src/main/java/com/rest/api/config/SwaggerConfiguration.java
Normal file
@@ -0,0 +1,30 @@
|
||||
package com.rest.api.config;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import springfox.documentation.builders.ApiInfoBuilder;
|
||||
import springfox.documentation.builders.PathSelectors;
|
||||
import springfox.documentation.builders.RequestHandlerSelectors;
|
||||
import springfox.documentation.service.ApiInfo;
|
||||
import springfox.documentation.spi.DocumentationType;
|
||||
import springfox.documentation.spring.web.plugins.Docket;
|
||||
import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
||||
|
||||
@Configuration
|
||||
@EnableSwagger2
|
||||
public class SwaggerConfiguration {
|
||||
@Bean
|
||||
public Docket swaggerApi() {
|
||||
return new Docket(DocumentationType.SWAGGER_2).apiInfo(swaggerInfo()).select()
|
||||
.apis(RequestHandlerSelectors.basePackage("com.rest.api.controller"))
|
||||
.paths(PathSelectors.any())
|
||||
.build()
|
||||
.useDefaultResponseMessages(false); // 기본으로 세팅되는 200,401,403,404 메시지를 표시 하지 않음
|
||||
}
|
||||
|
||||
private ApiInfo swaggerInfo() {
|
||||
return new ApiInfoBuilder().title("Spring API Documentation")
|
||||
.description("앱 개발시 사용되는 서버 API에 대한 연동 문서입니다")
|
||||
.license("happydaddy").licenseUrl("http://daddyprogrammer.org").version("1").build();
|
||||
}
|
||||
}
|
||||
@@ -2,31 +2,37 @@ package com.rest.api.controller.v1;
|
||||
|
||||
import com.rest.api.entity.User;
|
||||
import com.rest.api.repo.UserJpaRepo;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Api(tags = {"1. User"})
|
||||
@RequiredArgsConstructor
|
||||
@RestController // 결과값을 JSON으로 출력합니다.
|
||||
@RestController
|
||||
@RequestMapping(value = "/v1")
|
||||
public class UserController {
|
||||
|
||||
private final UserJpaRepo userJpaRepo;
|
||||
|
||||
@ApiOperation(value = "회원 조회", notes = "모든 회원을 조회한다")
|
||||
@GetMapping(value = "/user")
|
||||
public List<User> findAllUser() {
|
||||
return userJpaRepo.findAll();
|
||||
}
|
||||
|
||||
@ApiOperation(value = "회원 입력", notes = "회원을 입력한다.")
|
||||
@PostMapping(value = "/user")
|
||||
public User save() {
|
||||
public User save(@ApiParam(value = "회원아이디", required = true) @RequestParam String uid,
|
||||
@ApiParam(value = "회원이름", required = true) @RequestParam String name) {
|
||||
User user = User.builder()
|
||||
.uid("yumi@naver.com")
|
||||
.name("유미")
|
||||
.uid(uid)
|
||||
.name(name)
|
||||
.build();
|
||||
return userJpaRepo.save(user);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,13 @@
|
||||
package com.rest.api.entity;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
@@ -22,4 +30,4 @@ public class User {
|
||||
private String uid;
|
||||
@Column(nullable = false, length = 100) // name column을 명시합니다. 필수이고 길이는 100입니다.
|
||||
private String name;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,5 +8,8 @@ spring:
|
||||
username: sa
|
||||
jpa:
|
||||
database-platform: org.hibernate.dialect.H2Dialect
|
||||
properties.hibernate.hbm2ddl.auto: update
|
||||
showSql: true
|
||||
#properties.hibernate.hbm2ddl.auto: none
|
||||
showSql: true
|
||||
messages:
|
||||
basename: i18n/exception
|
||||
encoding: UTF-8
|
||||
Reference in New Issue
Block a user