@Test public void getAccount() throws Exception { mockMvc.perform(get("/account/{id}", -1)) .andDo(print()) .andExpect(MockMvcResultMatchers.status().isOk()) .andExpect(model().attribute("msg", "主键必须大于0")); Account account = new Account(1, "张三", 12.0); mockMvc.perform(get("/account/{id}", 1)) .andDo(print()) .andExpect(MockMvcResultMatchers.status().isOk()) .andExpect(content().json(JACKSON_MAPPER.writeValueAsString(ResultBean.success(account)))); }
@GetMapping("{id}") @ApiOperation(value = "通过id获取账户") public ResultBean<Account> getAccount(@ApiParam(name = "id", value = "账户id", required = true) @Positive(message = "主键必须大于0") @PathVariable("id") int id) { return ResultBean.success(accountService.getById(id)); }
AccountController { @GetMapping("{id}") @ApiOperation(value = "通过id获取账户") public ResultBean<Account> getAccount(@ApiParam(name = "id", value = "账户id", required = true) @Positive(message = "主键必须大于0") @PathVariable("id") int id) { return ResultBean.success(accountService.getById(id)); } }
AccountController { @GetMapping("{id}") @ApiOperation(value = "通过id获取账户") public ResultBean<Account> getAccount(@ApiParam(name = "id", value = "账户id", required = true) @Positive(message = "主键必须大于0") @PathVariable("id") int id) { return ResultBean.success(accountService.getById(id)); }  }
AccountController { @GetMapping("{id}") @ApiOperation(value = "通过id获取账户") public ResultBean<Account> getAccount(@ApiParam(name = "id", value = "账户id", required = true) @Positive(message = "主键必须大于0") @PathVariable("id") int id) { return ResultBean.success(accountService.getById(id)); }  @GetMapping("{id}") @ApiOperation(value = "通过id获取账户") ResultBean<Account> getAccount(@ApiParam(name = "id", value = "账户id", required = true)
                                          @Positive(message = "主键必须大于0")
                                          @PathVariable("id") int id); @GetMapping(value = "get") @ApiOperation(value = "新增账户", notes = "返回新生成的主键id") @ApiImplicitParams({ @ApiImplicitParam(paramType = "body", name = "account", value = "account帐号信息", dataType = "Account"), }) ResultBean<Integer> get(@Valid @RequestParam Account account); @PostMapping(value = "add", consumes = MediaType.APPLICATION_JSON_UTF8_VALUE) @ApiOperation(value = "新增账户", notes = "返回新生成的主键id") ResultBean<Integer> add(@Valid @RequestBody Account account); @PostMapping(value = "add2", consumes = MediaType.APPLICATION_JSON_UTF8_VALUE) @ApiOperation(value = "新增账户", notes = "返回新生成的主键id") ResultBean<Integer> add2(@Validated(Insert.class) @RequestBody Account account); @GetMapping("/testBusinessException") @ApiOperation(value = "用于测试抛出一个业务异常") ResultBean<?> testBusinessException(); @GetMapping("/testUnknownException") @ApiOperation(value = "用于测试抛出一个未知异常") ResultBean<?> testUnknownException(); void test4(); }
AccountController { @GetMapping("{id}") @ApiOperation(value = "通过id获取账户") public ResultBean<Account> getAccount(@ApiParam(name = "id", value = "账户id", required = true) @Positive(message = "主键必须大于0") @PathVariable("id") int id) { return ResultBean.success(accountService.getById(id)); }  @GetMapping("{id}") @ApiOperation(value = "通过id获取账户") ResultBean<Account> getAccount(@ApiParam(name = "id", value = "账户id", required = true)
                                          @Positive(message = "主键必须大于0")
                                          @PathVariable("id") int id); @GetMapping(value = "get") @ApiOperation(value = "新增账户", notes = "返回新生成的主键id") @ApiImplicitParams({ @ApiImplicitParam(paramType = "body", name = "account", value = "account帐号信息", dataType = "Account"), }) ResultBean<Integer> get(@Valid @RequestParam Account account); @PostMapping(value = "add", consumes = MediaType.APPLICATION_JSON_UTF8_VALUE) @ApiOperation(value = "新增账户", notes = "返回新生成的主键id") ResultBean<Integer> add(@Valid @RequestBody Account account); @PostMapping(value = "add2", consumes = MediaType.APPLICATION_JSON_UTF8_VALUE) @ApiOperation(value = "新增账户", notes = "返回新生成的主键id") ResultBean<Integer> add2(@Validated(Insert.class) @RequestBody Account account); @GetMapping("/testBusinessException") @ApiOperation(value = "用于测试抛出一个业务异常") ResultBean<?> testBusinessException(); @GetMapping("/testUnknownException") @ApiOperation(value = "用于测试抛出一个未知异常") ResultBean<?> testUnknownException(); void test4();  }