Search in sources :

Example 6 with BookDTO

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;
}
Also used : BookDTO(com.github.lybgeek.redis.dto.BookDTO) Book(com.github.lybgeek.redis.model.Book) Cacheable(org.springframework.cache.annotation.Cacheable)

Example 7 with 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;
}
Also used : BookDTO(com.github.lybgeek.redis.dto.BookDTO) Result(com.github.lybgeek.common.model.Result) PageResult(com.github.lybgeek.common.model.PageResult) BindingResult(org.springframework.validation.BindingResult) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 8 with BookDTO

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;
}
Also used : BookDTO(com.github.lybgeek.redis.dto.BookDTO) Book(com.github.lybgeek.redis.model.Book) BizException(com.github.lybgeek.common.exception.BizException) Date(java.util.Date) Cacheable(org.springframework.cache.annotation.Cacheable) Transactional(org.springframework.transaction.annotation.Transactional)

Example 9 with 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));
}
Also used : BookDTO(com.github.lybgeek.redis.dto.BookDTO) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 10 with BookDTO

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);
}
Also used : BookDTO(com.github.lybgeek.redis.dto.BookDTO) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

BookDTO (com.github.lybgeek.redis.dto.BookDTO)11 Test (org.junit.Test)6 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)6 Book (com.github.lybgeek.redis.model.Book)3 PageResult (com.github.lybgeek.common.model.PageResult)2 Result (com.github.lybgeek.common.model.Result)2 Cacheable (org.springframework.cache.annotation.Cacheable)2 BindingResult (org.springframework.validation.BindingResult)2 PostMapping (org.springframework.web.bind.annotation.PostMapping)2 IPage (com.baomidou.mybatisplus.core.metadata.IPage)1 Page (com.baomidou.mybatisplus.extension.plugins.pagination.Page)1 BizException (com.github.lybgeek.common.exception.BizException)1 PageQuery (com.github.lybgeek.common.model.PageQuery)1 RedisCache (com.github.lybgeek.redis.annotation.RedisCache)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 Transactional (org.springframework.transaction.annotation.Transactional)1