use of com.github.lybgeek.spilt.dto.BookDTO 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.spilt.dto.BookDTO in project springboot-learning by lyb-geek.
the class SplitTableApplicationTest method testListBook.
@Test
public void testListBook() {
BookDTO bookDTO = new BookDTO();
bookDTO.setAuthor("张三");
bookDTO.setBookName("docker");
// bookDTO.setId(5L);
List<BookDTO> bookDTOS = bookService.listBooks(bookDTO);
if (CollectionUtils.isNotEmpty(bookDTOS)) {
bookDTOS.forEach(book -> System.out.println(book));
}
}
use of com.github.lybgeek.spilt.dto.BookDTO in project springboot-learning by lyb-geek.
the class BookServiceImpl method addBook.
@Override
@Transactional
public // @DS("follow")
BookDTO addBook(BookDTO bookDTO) {
Book book = dozerMapper.map(bookDTO, Book.class);
boolean isExitBookByName = ObjectUtils.isNotEmpty(getBookByName(bookDTO.getBookName()));
if (isExitBookByName) {
throw new BizException("书名已经存在");
}
book.setCreateDate(new Date());
book.setUpdateDate(new Date());
baseMapper.insert(book);
bookDTO = dozerMapper.map(book, BookDTO.class);
return bookDTO;
}
use of com.github.lybgeek.spilt.dto.BookDTO in project springboot-learning by lyb-geek.
the class BookServiceImpl method pageBook.
@Override
public PageResult<BookDTO> pageBook(PageQuery<BookDTO> pageQuery) {
BookDTO bookDTO = pageQuery.getQueryParams();
Wrapper<Book> wrapper = wrapperQueryCondition(bookDTO);
IPage<Book> page = new Page<>(pageQuery.getPageNo(), pageQuery.getPageSize());
IPage<Book> bookIPage = baseMapper.selectPage(page, wrapper);
if (bookIPage != null) {
List<BookDTO> bookDTOS = new ArrayList<>();
if (CollectionUtils.isNotEmpty(bookIPage.getRecords())) {
bookDTOS = BeanMapperUtils.mapList(bookIPage.getRecords(), BookDTO.class);
}
return PageUtil.INSTANCE.getPage(bookIPage, bookDTOS);
}
return null;
}
use of com.github.lybgeek.spilt.dto.BookDTO in project springboot-learning by lyb-geek.
the class BookServiceImpl method getBookById.
@Override
public BookDTO getBookById(Long id) {
Book dbBook = baseMapper.selectById(id);
BookDTO bookDTO = dozerMapper.map(dbBook, BookDTO.class);
return bookDTO;
}
Aggregations