use of com.github.lybgeek.redis.dto.BookDTO in project springboot-learning by lyb-geek.
the class BookServiceImpl method getBookById.
@Override
@Cacheable(cacheNames = "book", key = "#id", unless = "#result == null")
public BookDTO getBookById(Long id) {
log.info("getBookById走db");
Book dbBook = baseMapper.selectById(id);
BookDTO bookDTO = dozerMapper.map(dbBook, BookDTO.class);
return bookDTO;
}
use of com.github.lybgeek.redis.dto.BookDTO 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.redis.dto.BookDTO in project springboot-learning by lyb-geek.
the class BookServiceImpl method addBook.
@Override
@Transactional
@Cacheable(cacheNames = "book", key = "'add_'+#bookDTO.bookName")
public 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.redis.dto.BookDTO in project springboot-learning by lyb-geek.
the class RedisApplicationTest method testListBook.
@Test
public void testListBook() {
BookDTO bookDTO = new BookDTO();
bookDTO.setAuthor("张三");
bookDTO.setBookName("java");
// bookDTO.setId(5L);
List<BookDTO> bookDTOS = bookService.listBooks(bookDTO);
bookDTOS.forEach(book -> System.out.println(book));
}
use of com.github.lybgeek.redis.dto.BookDTO in project springboot-learning by lyb-geek.
the class RedisApplicationTest method testGetBook.
@Test
public void testGetBook() {
BookDTO bookDTO = bookService.getBookById(1L);
Assert.assertNotNull(bookDTO);
System.out.println(bookDTO);
}
Aggregations