From e93548c493150ca556a99fa6e79a3891e8c104a8 Mon Sep 17 00:00:00 2001 From: Lim Jonguk Date: Sun, 9 Jan 2022 22:54:45 +0900 Subject: [PATCH] return type xml sample add --- build.gradle | 27 ++++++++++--------- .../com/xit/core/api/RestErrorResponse.java | 7 ----- .../java/com/xit/core/api/RestResponse.java | 2 -- .../oauth2/api/controller/UserController.java | 8 +++++- 4 files changed, 21 insertions(+), 23 deletions(-) diff --git a/build.gradle b/build.gradle index 4493f5a..a76e217 100644 --- a/build.gradle +++ b/build.gradle @@ -76,7 +76,7 @@ dependencies { implementation 'org.springframework.boot:spring-boot-starter-jdbc' // yaml 다국화 lib - implementation 'net.rakugakibox.util:yaml-resource-bundle:1.1' + implementation 'net.rakugakibox.util:yaml-resource-bundle:1.2' // spring-boot 2.3 까지는 사용 불가 - spring-boot-starter-web에 포함되어 있다 // hibernate-validator:5.2.4.Final 사용 @@ -116,23 +116,23 @@ dependencies { //compileOnly 'com.querydsl:querydsl-apt' // JPA mapstruct : lombok 과 함께 사용시 반드시 순서 지겨야 함다 - lombok이 먼저 선언된 경우 - implementation 'org.projectlombok:lombok-mapstruct-binding:0.2.0' - implementation 'org.projectlombok:lombok' - implementation 'org.mapstruct:mapstruct:1.4.2.Final' - annotationProcessor "org.projectlombok:lombok-mapstruct-binding:0.2.0" - annotationProcessor 'org.projectlombok:lombok' - annotationProcessor 'org.mapstruct:mapstruct-processor:1.4.2.Final' +// implementation 'org.projectlombok:lombok-mapstruct-binding:0.2.0' +// implementation 'org.projectlombok:lombok' +// implementation 'org.mapstruct:mapstruct:1.4.2.Final' +// annotationProcessor "org.projectlombok:lombok-mapstruct-binding:0.2.0" +// annotationProcessor 'org.projectlombok:lombok' +// annotationProcessor 'org.mapstruct:mapstruct-processor:1.4.2.Final' // JPA mapstruct : lombok 과 함께 사용시 반드시 순서 지겨야 함다 - ㅡmapstruct이 먼저 선언된 경우 // target class 에 @Builder 가 있어도 무시하고 생성자 + setter 를 사용하므로 정상적으로 Mapper 클래스를 Generation 하기 위해서 // @NoArgsConstructor, @Setter 가 필요 // but, 최근 Setter 사용을 지양하는 추세라 mapstruct를 먼저 오도록 해서 @Builder 방식으로 Generation -// implementation 'org.mapstruct:mapstruct:1.4.2.Final' -// implementation 'org.projectlombok:lombok-mapstruct-binding:0.2.0' -// implementation 'org.projectlombok:lombok' -// annotationProcessor 'org.mapstruct:mapstruct-processor:1.4.2.Final' -// annotationProcessor "org.projectlombok:lombok-mapstruct-binding:0.2.0" -// annotationProcessor 'org.projectlombok:lombok' + implementation 'org.mapstruct:mapstruct:1.4.2.Final' + implementation 'org.projectlombok:lombok-mapstruct-binding:0.2.0' + implementation 'org.projectlombok:lombok' + annotationProcessor 'org.mapstruct:mapstruct-processor:1.4.2.Final' + annotationProcessor "org.projectlombok:lombok-mapstruct-binding:0.2.0" + annotationProcessor 'org.projectlombok:lombok' //-----------------------------------------------------------------------------------// //-----------------------------------------------------------------------------------// @@ -212,6 +212,7 @@ dependencies { implementation 'com.fasterxml.jackson.module:jackson-module-afterburner:2.13.1' implementation 'com.fasterxml.jackson.core:jackson-databind:2.13.1' implementation 'com.fasterxml.jackson.datatype:jackson-datatype-joda:2.13.1' + implementation 'javax.xml.bind:jaxb-api:2.3.1' //implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.12.5' //-----------------------------------------------------------------------------------// diff --git a/src/main/java/com/xit/core/api/RestErrorResponse.java b/src/main/java/com/xit/core/api/RestErrorResponse.java index 65264c4..6c3e383 100644 --- a/src/main/java/com/xit/core/api/RestErrorResponse.java +++ b/src/main/java/com/xit/core/api/RestErrorResponse.java @@ -11,19 +11,12 @@ import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; -import org.springframework.validation.FieldError; -import org.springframework.web.bind.MethodArgumentNotValidException; -import javax.xml.bind.annotation.XmlRootElement; import java.io.Serializable; import java.time.LocalDateTime; -import java.util.*; - -import static java.util.stream.Collectors.toMap; @Schema(name = "RestError", description = "Restful API 에러", implementation = IRestResponse.class) @JacksonXmlRootElement(localName = "result") -@XmlRootElement(name = "result") @Slf4j @Getter @Builder diff --git a/src/main/java/com/xit/core/api/RestResponse.java b/src/main/java/com/xit/core/api/RestResponse.java index d359d58..124f226 100644 --- a/src/main/java/com/xit/core/api/RestResponse.java +++ b/src/main/java/com/xit/core/api/RestResponse.java @@ -14,7 +14,6 @@ import org.springframework.data.domain.Page; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; -import javax.xml.bind.annotation.XmlRootElement; import java.io.Serializable; import java.util.Collection; import java.util.HashMap; @@ -23,7 +22,6 @@ import java.util.Map; @Schema(name = "RestResult", description = "Restful API 결과", implementation = IRestResponse.class) @Getter @Setter @JacksonXmlRootElement(localName = "result") -@XmlRootElement(name = "result") @SuppressWarnings("rawtypes") public class RestResponse implements IRestResponse, Serializable { private static final long SerialVersionUID = 1L; diff --git a/src/main/java/com/xit/core/oauth2/api/controller/UserController.java b/src/main/java/com/xit/core/oauth2/api/controller/UserController.java index 0fe28ea..12662f2 100644 --- a/src/main/java/com/xit/core/oauth2/api/controller/UserController.java +++ b/src/main/java/com/xit/core/oauth2/api/controller/UserController.java @@ -17,6 +17,7 @@ import io.swagger.v3.oas.annotations.enums.ParameterIn; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; import org.mapstruct.factory.Mappers; +import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.*; @@ -38,11 +39,16 @@ public class UserController { private CmmUserMapstruct mapstruct = Mappers.getMapper(CmmUserMapstruct.class); @Operation(summary = "회원 가입" , description = "신규 회원 등록") - @PostMapping("/signup") // @Valid + @PostMapping(value = "/signup", consumes = MediaType.APPLICATION_JSON_VALUE) // @Valid public ResponseEntity signup(@RequestBody @Valid final CmmUserDto cmmUserDto) { return RestResponse.of(userService.signup(mapstruct.toEntity(cmmUserDto))); } + @Operation(summary = "회원 가입" , description = "신규 회원 등록- result xml return") + @PostMapping(value = "/signupXml", consumes = {MediaType.APPLICATION_JSON_VALUE}, produces = MediaType.APPLICATION_XML_VALUE) // @Valid + public ResponseEntity signupXml(@RequestBody @Valid final CmmUserDto cmmUserDto) { + return RestResponse.of(userService.signup(mapstruct.toEntity(cmmUserDto))); + } @GetMapping public ResponseEntity getUser(HttpServletRequest request) {