SpringBoot2로 Rest api 만들기(7) – MessageSource를 이용한 Exception 처리
This commit is contained in:
@@ -13,6 +13,8 @@ import io.swagger.annotations.ApiParam;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
@Api(tags = {"1. User"})
|
||||
@RequiredArgsConstructor
|
||||
@RestController
|
||||
@@ -31,9 +33,9 @@ public class UserController {
|
||||
|
||||
@ApiOperation(value = "회원 단건 조회", notes = "userId로 회원을 조회한다")
|
||||
@GetMapping(value = "/user/{userId}")
|
||||
public BasicResult<User> findUserById(@ApiParam(value = "회원ID", required = true) @RequestParam int userId) {
|
||||
public BasicResult<User> findUserById(@ApiParam(value = "회원ID", required = true) @PathVariable int userId,
|
||||
@ApiParam(value = "언어", defaultValue = "ko") @RequestParam String lang) {
|
||||
// 결과데이터가 단일건인경우 getBasicResult를 이용해서 결과를 출력한다.
|
||||
// return responseService.getBasicResult(userJpaRepo.findById(userId).orElse(null));
|
||||
return responseService.getBasicResult(userJpaRepo.findById(userId).orElseThrow(CUserNotFoundException::new));
|
||||
}
|
||||
|
||||
@@ -63,7 +65,7 @@ public class UserController {
|
||||
@ApiOperation(value = "회원 삭제", notes = "userId로 회원정보를 삭제한다")
|
||||
@DeleteMapping(value = "/user/{userId}")
|
||||
public CommonResult delete(
|
||||
@ApiParam(value = "회원ID", required = true) @RequestParam int userId) {
|
||||
@ApiParam(value = "회원ID", required = true) @PathVariable int userId) {
|
||||
userJpaRepo.deleteById(userId);
|
||||
// 성공 결과 정보만 필요한경우 getSuccessResult()를 이용하여 결과를 출력한다.
|
||||
return responseService.getSuccessResult();
|
||||
|
||||
Reference in New Issue
Block a user