Search in sources :

Example 1 with BookDTO

use of com.github.lybgeek.httpclient.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.httpclient.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.httpclient.dto.BookDTO in project springboot-learning by lyb-geek.

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

Example 3 with BookDTO

use of com.github.lybgeek.httpclient.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.httpclient.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 4 with BookDTO

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

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

Example 5 with BookDTO

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

the class HttpClientAppliactionTest method testPageBook.

@Test
public void testPageBook() {
    PageQuery pageQuery = new PageQuery<>().setPageNo(1).setPageSize(5);
    BookDTO bookDTO = new BookDTO();
    bookDTO.setAuthor("张三");
    // bookDTO.setBookName("图解Http");
    // bookDTO.setId(4L);
    pageQuery.setQueryParams(bookDTO);
    PageResult<BookDTO> pageResult = bookService.pageBook(pageQuery);
    if (pageResult != null) {
        pageResult.getList().forEach(book -> System.out.println(book));
    }
}
Also used : PageQuery(com.github.lybgeek.common.model.PageQuery) BookDTO(com.github.lybgeek.httpclient.dto.BookDTO) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

BookDTO (com.github.lybgeek.httpclient.dto.BookDTO)6 Test (org.junit.Test)4 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)4 PageResult (com.github.lybgeek.common.model.PageResult)2 Result (com.github.lybgeek.common.model.Result)2 BindingResult (org.springframework.validation.BindingResult)2 PostMapping (org.springframework.web.bind.annotation.PostMapping)2 PageQuery (com.github.lybgeek.common.model.PageQuery)1