use of com.github.lybgeek.common.model.Result in project springboot-learning by lyb-geek.
the class BookController method addBook.
@PostMapping(value = "/add")
public Result<BookDTO> addBook(@Valid BookDTO bookDTO, BindingResult bindingResult) {
Result<BookDTO> result = new Result<>();
if (bindingResult.hasErrors()) {
return ResultUtil.INSTANCE.getFailResult(bindingResult, result);
}
try {
BookDTO book = bookService.addBook(bookDTO);
result.setData(book);
} catch (Exception e) {
log.error("addBook error:" + e.getMessage(), e);
result.setStatus(Result.fail);
result.setMessage(e.getMessage());
}
return result;
}
use of com.github.lybgeek.common.model.Result in project springboot-learning by lyb-geek.
the class BookController method upadteBook.
@PostMapping(value = "/update")
@ApiOperation(value = "更新书籍", notes = "更新书籍")
public Result<BookDTO> upadteBook(BookDTO bookDTO) {
Result<BookDTO> result = new Result<>();
if (bookDTO.getId() == null) {
result.setStatus(Result.fail);
result.setMessage("id不能为空");
return result;
}
BookDTO book = bookService.editBook(bookDTO);
result.setData(book);
return result;
}
use of com.github.lybgeek.common.model.Result in project springboot-learning by lyb-geek.
the class ResponseAdvice method methodArgumentNotValidExceptionExceptionHandler.
/**
* 针对Validate校验异常统一处理
* @param request
* @param methodArgumentNotValidException
* @return
*/
@ExceptionHandler(MethodArgumentNotValidException.class)
@ResponseStatus(code = HttpStatus.BAD_REQUEST)
public Result<?> methodArgumentNotValidExceptionExceptionHandler(HttpServletRequest request, MethodArgumentNotValidException methodArgumentNotValidException) {
Result result = new Result();
log.error("catch methodArgumentNotValidException :" + methodArgumentNotValidException.getMessage(), methodArgumentNotValidException);
return ResultUtils.INSTANCE.getFailResult(methodArgumentNotValidException.getBindingResult(), result);
}
use of com.github.lybgeek.common.model.Result in project springboot-learning by lyb-geek.
the class BookController method upadteBook.
@PostMapping(value = "/update")
public Result<BookDTO> upadteBook(BookDTO bookDTO) {
Result<BookDTO> result = new Result<>();
if (bookDTO.getId() == null) {
result.setStatus(Result.fail);
result.setMessage("id不能为空");
return result;
}
BookDTO book = bookService.editBook(bookDTO);
result.setData(book);
return result;
}
use of com.github.lybgeek.common.model.Result in project springboot-learning by lyb-geek.
the class BookController method addBook.
@PostMapping(value = "/add")
@ApiOperation(value = "添加书籍", notes = "添加书籍")
public Result<BookDTO> addBook(@Valid BookDTO bookDTO, BindingResult bindingResult) {
Result<BookDTO> result = new Result<>();
if (bindingResult.hasErrors()) {
return ResultUtil.INSTANCE.getFailResult(bindingResult, result);
}
try {
BookDTO book = bookService.addBook(bookDTO);
result.setData(book);
} catch (Exception e) {
log.error("addBook error:" + e.getMessage(), e);
result.setStatus(Result.fail);
result.setMessage(e.getMessage());
}
return result;
}
Aggregations