use of com.github.lybgeek.common.model.Result in project springboot-learning by lyb-geek.
the class BookController method getBookById.
@PostMapping(value = "/get/{id}")
@ApiOperation(value = "查找书籍", notes = "根据书籍编号查找书籍")
@ApiImplicitParams({ @ApiImplicitParam(name = "id", value = "书籍编号", dataType = "Long", required = true) })
public Result<BookDTO> getBookById(@PathVariable("id") Long id) {
Result<BookDTO> result = new Result<>();
BookDTO book = bookService.getBookById(id);
result.setData(book);
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")
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 BizExceptionHandler method handleException.
@ExceptionHandler(Exception.class)
public Result handleException(Exception e) {
log.error(e.getMessage(), e);
Result result = Result.builder().status(Result.fail).message(e.getMessage()).build();
return result;
}
use of com.github.lybgeek.common.model.Result in project springboot-learning by lyb-geek.
the class ImageController method importImage.
@PostMapping(value = "/import")
@ResponseBody
public Result<ImageDTO> importImage(MultipartFile file) throws Exception {
ExcelImportResult<ImageVO> excelData = ExcelReader.builder().headRowNumber(1).sheetNo(0).inputStream(file.getInputStream()).build().read(ImageVO.class, true);
boolean verifyFail = excelData.isVerifyFail();
if (verifyFail) {
String errorMsg = ExcelUtils.getErrorMsg(excelData.getFailList());
throw new BizException(errorMsg);
}
List<ImageDTO> imageDTOS = imageConvertMapper.listImageVO2ListDTO(excelData.getList());
imageService.saveImages(imageDTOS);
Result result = Result.builder().data(imageDTOS).build();
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")
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