Search in sources :

Example 1 with BookDTO

use of com.github.lybgeek.redis.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;
}
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 2 with BookDTO

use of com.github.lybgeek.redis.dto.BookDTO in project springboot-learning by lyb-geek.

the class RedisApplicationTest method testUpdateBook.

@Test
public void testUpdateBook() {
    BookDTO bookDTO = BookDTO.builder().id(9L).bookName("docker实战").author("大神").description("docker实战系列教程").price(BigDecimal.valueOf(23.2)).stock(1).build();
    bookDTO = bookService.editBook(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)

Example 3 with BookDTO

use of com.github.lybgeek.redis.dto.BookDTO in project springboot-learning by lyb-geek.

the class RedisApplicationTest method testAddBook.

@Test
public void testAddBook() {
    for (int i = 1; i <= 10; i++) {
        BookDTO bookDTO = BookDTO.builder().bookName("java从入门到精通(第" + i + ")版").author("张三" + i).description("java从入门到精通(第" + i + ")版,热门系列").price(BigDecimal.valueOf(i * 10)).stock(i).build();
        bookDTO = bookService.addBook(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)

Example 4 with BookDTO

use of com.github.lybgeek.redis.dto.BookDTO in project springboot-learning by lyb-geek.

the class RedisApplicationTest method testSaveBook.

@Test
public void testSaveBook() {
    BookDTO bookDTO = BookDTO.builder().bookName("netty从入门到精通版第一版").author("张三").description("netty从入门到精通,热门系列").price(BigDecimal.valueOf(10)).stock(10).build();
    bookDTO = bookService.addBook(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)

Example 5 with BookDTO

use of com.github.lybgeek.redis.dto.BookDTO in project springboot-learning by lyb-geek.

the class BookServiceImpl method pageBook.

@Override
@RedisCache(type = CacheOperateType.QUERY, cacheKeyPrefix = "pageBook", expireTime = 180)
public PageResult<BookDTO> pageBook(PageQuery<BookDTO> pageQuery) {
    log.info("pageBook走db");
    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;
}
Also used : BookDTO(com.github.lybgeek.redis.dto.BookDTO) Book(com.github.lybgeek.redis.model.Book) ArrayList(java.util.ArrayList) Page(com.baomidou.mybatisplus.extension.plugins.pagination.Page) IPage(com.baomidou.mybatisplus.core.metadata.IPage) RedisCache(com.github.lybgeek.redis.annotation.RedisCache)

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