Search in sources :

Example 1 with BookDTO

use of com.github.lybgeek.orm.mybatisplus.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;
}
Also used : BookDTO(com.github.lybgeek.orm.mybatisplus.dto.BookDTO) Book(com.github.lybgeek.orm.mybatisplus.model.Book)

Example 2 with BookDTO

use of com.github.lybgeek.orm.mybatisplus.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.orm.mybatisplus.dto.BookDTO) BindingResult(org.springframework.validation.BindingResult) Result(com.github.lybgeek.orm.common.model.Result) PageResult(com.github.lybgeek.orm.common.model.PageResult) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 3 with BookDTO

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

the class OrmApplicationTest method testUpdateBook.

@Test
public void testUpdateBook() {
    BookDTO bookDTO = BookDTO.builder().id(1L).bookName("图解Http").author("大神").description("http入门系列教程").price(BigDecimal.valueOf(23.2)).stock(1).build();
    bookDTO = bookService.editBook(bookDTO);
    System.out.println(bookDTO);
}
Also used : BookDTO(com.github.lybgeek.orm.mybatisplus.dto.BookDTO) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 4 with BookDTO

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

the class OrmApplicationTest 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.orm.mybatisplus.dto.BookDTO) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 5 with BookDTO

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

the class BookServiceImpl method addBook.

@Override
@Transactional
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.orm.mybatisplus.dto.BookDTO) Book(com.github.lybgeek.orm.mybatisplus.model.Book) BizException(com.github.lybgeek.orm.common.exception.BizException) Date(java.util.Date) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

BookDTO (com.github.lybgeek.orm.mybatisplus.dto.BookDTO)10 Test (org.junit.Test)4 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)4 Book (com.github.lybgeek.orm.mybatisplus.model.Book)3 BizException (com.github.lybgeek.orm.common.exception.BizException)2 PageResult (com.github.lybgeek.orm.common.model.PageResult)2 Result (com.github.lybgeek.orm.common.model.Result)2 Transactional (org.springframework.transaction.annotation.Transactional)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 PageQuery (com.github.lybgeek.orm.common.model.PageQuery)1 OrderItemsDTO (com.github.lybgeek.orm.mybatis.dto.OrderItemsDTO)1 BookOrder (com.github.lybgeek.orm.mybatis.model.BookOrder)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1