From 5d1bcde6e4d00620fcc7e7c7a89bda7d5ea5b84c Mon Sep 17 00:00:00 2001 From: liuxm <liuxm_a@163.com> Date: 星期三, 12 六月 2024 10:08:39 +0800 Subject: [PATCH] 添加验证和异常处理 --- pms-parent/pms-web-platform/src/main/java/com/dy/pmsPlatform/proLine/ProLineCtrl.java | 68 ++++++--------------------------- 1 files changed, 13 insertions(+), 55 deletions(-) diff --git a/pms-parent/pms-web-platform/src/main/java/com/dy/pmsPlatform/proLine/ProLineCtrl.java b/pms-parent/pms-web-platform/src/main/java/com/dy/pmsPlatform/proLine/ProLineCtrl.java index f319e04..3ea503b 100644 --- a/pms-parent/pms-web-platform/src/main/java/com/dy/pmsPlatform/proLine/ProLineCtrl.java +++ b/pms-parent/pms-web-platform/src/main/java/com/dy/pmsPlatform/proLine/ProLineCtrl.java @@ -10,7 +10,6 @@ import jakarta.validation.Valid; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.validation.BindingResult; import org.springframework.web.bind.annotation.*; import java.util.List; @@ -33,25 +32,15 @@ /** * 淇濆瓨 * @param line - * @param bindingResult * @return */ @PostMapping(path="save") @SsoPowerAop(power = "10300005") @Log("淇濆瓨鐢熶骇绾�") - public BaseResponse<Boolean> save(@RequestBody @Valid PltProductionLine line,BindingResult bindingResult){ - int count; - try { - if (bindingResult != null && bindingResult.hasErrors()) { - return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); - } - line.disabled = false; - line.deleted = false; - count = sv.save(line); - }catch (Exception e){ - log.error("淇濆瓨鐢熶骇绾垮紓甯�", e); - return BaseResponseUtils.buildException(e.getMessage()); - } + public BaseResponse<Boolean> save(@RequestBody @Valid PltProductionLine line){ + line.disabled = false; + line.deleted = false; + int count = sv.save(line); if (count <= 0) { return BaseResponseUtils.buildFail("鏁版嵁搴撳瓨鍌ㄥけ璐�"); } else { @@ -63,23 +52,13 @@ /** * 鏇存柊 * @param line - * @param bindingResult * @return */ @PostMapping(path="update") @SsoPowerAop(power = "10300005") @Log("鏇存柊鐢熶骇绾�") - public BaseResponse<Boolean> update(@RequestBody @Valid PltProductionLine line,BindingResult bindingResult){ - int count; - try { - if (bindingResult != null && bindingResult.hasErrors()) { - return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); - } - count = sv.update(line); - }catch (Exception e){ - log.error("鏇存柊鐢熶骇绾垮紓甯�", e); - return BaseResponseUtils.buildException(e.getMessage()); - } + public BaseResponse<Boolean> update(@RequestBody @Valid PltProductionLine line){ + int count = sv.update(line); if (count <= 0) { return BaseResponseUtils.buildFail("鏁版嵁搴撳瓨鍌ㄥけ璐�"); } else { @@ -96,13 +75,7 @@ @SsoPowerAop(power = "10300005") @Log("鍒犻櫎鐢熶骇绾�") public BaseResponse<Boolean> delete(String id){ - int count; - try { - count = sv.delete(Long.parseLong(id)); - }catch (Exception e){ - log.error("鍒犻櫎鐢熶骇绾垮紓甯�", e); - return BaseResponseUtils.buildException(e.getMessage()); - } + int count = sv.delete(Long.parseLong(id)); if (count <= 0) { return BaseResponseUtils.buildFail("鏁版嵁搴撳瓨鍌ㄥけ璐�"); } else { @@ -120,13 +93,8 @@ @SsoPowerAop(power = "10300004") //鐧诲綍涓庢潈闄愬悓鏃堕獙璇� @Log("鏍规嵁ID鏌ヨ鐢熶骇绾�") public BaseResponse<PltProductionLine> one(String id){ - try{ - PltProductionLine param=sv.selectById(id); - return BaseResponseUtils.buildSuccess(JSON.toJSON(param)); - }catch (Exception e){ - log.error("鏍规嵁ID鏌ヨ鐢熶骇绾垮紓甯�", e); - return BaseResponseUtils.buildException(e.getMessage()); - } + PltProductionLine param=sv.selectById(id); + return BaseResponseUtils.buildSuccess(JSON.toJSON(param)); } /** @@ -138,13 +106,8 @@ @SsoPowerAop(power = "10300004") @Log("鍒嗛〉鏌ヨ鐢熶骇绾�") public BaseResponse<QueryResultVo<List<PltProductionLine>>> some(@RequestBody QueryVo vo){ - try { - QueryResultVo<List<PltProductionLine>> list = sv.selectSome(vo) ; - return BaseResponseUtils.buildSuccess(list); - }catch (Exception e){ - log.error("鍒嗛〉鏌ヨ鐢熶骇绾垮紓甯�", e); - return BaseResponseUtils.buildException(e.getMessage()); - } + QueryResultVo<List<PltProductionLine>> list = sv.selectSome(vo) ; + return BaseResponseUtils.buildSuccess(list); } /** @@ -155,14 +118,9 @@ @SsoPowerAop(power = "10300004") @Log("鏌ヨ鎵�鏈夌敓浜х嚎") public BaseResponse<List<PltProductionLine>> all(){ - try { - List<PltProductionLine> list = sv.selectAll(); + List<PltProductionLine> list = sv.selectAll(); - return BaseResponseUtils.buildSuccess(list); - }catch (Exception e){ - log.error("鏌ヨ鎵�鏈夌敓浜х嚎寮傚父", e); - return BaseResponseUtils.buildException(e.getMessage()); - } + return BaseResponseUtils.buildSuccess(list); } } -- Gitblit v1.8.0