@Test public void updateBook() throws Exception { BookDO bookDO = new BookDO(); bookDO.setTitle(title); bookDO.setAuthor(author); bookDO.setImage(image); bookDO.setSummary(summary); bookMapper.insert(bookDO); this.id = bookDO.getId(); CreateOrUpdateBookDTO dto = new CreateOrUpdateBookDTO(); dto.setAuthor(author); dto.setImage(image); dto.setSummary(summary); dto.setTitle(title + "lol"); ObjectMapper mapper = new ObjectMapper(); mapper.setPropertyNamingStrategy(PropertyNamingStrategy.CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES); String content = mapper.writeValueAsString(dto); mvc.perform(put("/v1/book/" + this.id) .contentType(MediaType.APPLICATION_JSON).content(content)) .andDo(print()) .andExpect(status().isOk()) .andExpect(MockMvcResultMatchers. jsonPath("$.message").value("更新图书成功")); }
@PutMapping("/{id}") public UnifyResponseVO updateBook(@PathVariable("id") @Positive(message = "{id}") Long id, @RequestBody @Validated CreateOrUpdateBookDTO validator) { BookDO book = bookService.getById(id); if (book == null) { throw new NotFoundException("book not found", 10022); } bookService.updateBook(book, validator); return ResponseUtil.generateUnifyResponse(11); }
BookController { @PutMapping("/{id}") public UnifyResponseVO updateBook(@PathVariable("id") @Positive(message = "{id}") Long id, @RequestBody @Validated CreateOrUpdateBookDTO validator) { BookDO book = bookService.getById(id); if (book == null) { throw new NotFoundException("book not found", 10022); } bookService.updateBook(book, validator); return ResponseUtil.generateUnifyResponse(11); } }
BookController { @PutMapping("/{id}") public UnifyResponseVO updateBook(@PathVariable("id") @Positive(message = "{id}") Long id, @RequestBody @Validated CreateOrUpdateBookDTO validator) { BookDO book = bookService.getById(id); if (book == null) { throw new NotFoundException("book not found", 10022); } bookService.updateBook(book, validator); return ResponseUtil.generateUnifyResponse(11); }  }
BookController { @PutMapping("/{id}") public UnifyResponseVO updateBook(@PathVariable("id") @Positive(message = "{id}") Long id, @RequestBody @Validated CreateOrUpdateBookDTO validator) { BookDO book = bookService.getById(id); if (book == null) { throw new NotFoundException("book not found", 10022); } bookService.updateBook(book, validator); return ResponseUtil.generateUnifyResponse(11); }  @GetMapping("/{id}") BookDO getBook(@PathVariable(value = "id") @Positive(message = "{id}") Long id); @GetMapping("") List<BookDO> getBooks(); @GetMapping("/search") List<BookDO> searchBook(@RequestParam(value = "q", required = false, defaultValue = "") String q); @PostMapping("") UnifyResponseVO createBook(@RequestBody @Validated CreateOrUpdateBookDTO validator); @PutMapping("/{id}") UnifyResponseVO updateBook(@PathVariable("id") @Positive(message = "{id}") Long id, @RequestBody @Validated CreateOrUpdateBookDTO validator); @DeleteMapping("/{id}") @RouteMeta(permission = "删除图书", module = "图书", mount = true) @GroupRequired UnifyResponseVO deleteBook(@PathVariable("id") @Positive(message = "{id}") Long id); }
BookController { @PutMapping("/{id}") public UnifyResponseVO updateBook(@PathVariable("id") @Positive(message = "{id}") Long id, @RequestBody @Validated CreateOrUpdateBookDTO validator) { BookDO book = bookService.getById(id); if (book == null) { throw new NotFoundException("book not found", 10022); } bookService.updateBook(book, validator); return ResponseUtil.generateUnifyResponse(11); }  @GetMapping("/{id}") BookDO getBook(@PathVariable(value = "id") @Positive(message = "{id}") Long id); @GetMapping("") List<BookDO> getBooks(); @GetMapping("/search") List<BookDO> searchBook(@RequestParam(value = "q", required = false, defaultValue = "") String q); @PostMapping("") UnifyResponseVO createBook(@RequestBody @Validated CreateOrUpdateBookDTO validator); @PutMapping("/{id}") UnifyResponseVO updateBook(@PathVariable("id") @Positive(message = "{id}") Long id, @RequestBody @Validated CreateOrUpdateBookDTO validator); @DeleteMapping("/{id}") @RouteMeta(permission = "删除图书", module = "图书", mount = true) @GroupRequired UnifyResponseVO deleteBook(@PathVariable("id") @Positive(message = "{id}") Long id);  }