@Test public void testList() throws Exception { ResultActions resultActions = mvc.perform(MockMvcRequestBuilders.get("/users")); resultActions.andExpect(MockMvcResultMatchers.status().isOk()); resultActions.andExpect(MockMvcResultMatchers.content().json("[\n" + " {\n" + " \"id\": 1,\n" + " \"username\": \"yudaoyuanma\"\n" + " },\n" + " {\n" + " \"id\": 2,\n" + " \"username\": \"woshiyutou\"\n" + " },\n" + " {\n" + " \"id\": 3,\n" + " \"username\": \"chifanshuijiao\"\n" + " }\n" + "]")); }
@GetMapping("") public List<UserVO> list() { List<UserVO> result = new ArrayList<>(); result.add(new UserVO().setId(1).setUsername("yudaoyuanma")); result.add(new UserVO().setId(2).setUsername("woshiyutou")); result.add(new UserVO().setId(3).setUsername("chifanshuijiao")); return result; }
UserController { @GetMapping("") public List<UserVO> list() { List<UserVO> result = new ArrayList<>(); result.add(new UserVO().setId(1).setUsername("yudaoyuanma")); result.add(new UserVO().setId(2).setUsername("woshiyutou")); result.add(new UserVO().setId(3).setUsername("chifanshuijiao")); return result; } }
UserController { @GetMapping("") public List<UserVO> list() { List<UserVO> result = new ArrayList<>(); result.add(new UserVO().setId(1).setUsername("yudaoyuanma")); result.add(new UserVO().setId(2).setUsername("woshiyutou")); result.add(new UserVO().setId(3).setUsername("chifanshuijiao")); return result; }  }
UserController { @GetMapping("") public List<UserVO> list() { List<UserVO> result = new ArrayList<>(); result.add(new UserVO().setId(1).setUsername("yudaoyuanma")); result.add(new UserVO().setId(2).setUsername("woshiyutou")); result.add(new UserVO().setId(3).setUsername("chifanshuijiao")); return result; }  @GetMapping("") List<UserVO> list(); @GetMapping("/{id}") UserVO get(@PathVariable("id") Integer id); @GetMapping("/v2/{id}") UserVO get2(@PathVariable("id") Integer id); @PostMapping("") Integer add(UserAddDTO addDTO); @PutMapping("/{id}") Boolean update(@PathVariable("id") Integer id, UserUpdateDTO updateDTO); @DeleteMapping("/{id}") Boolean delete(@PathVariable("id") Integer id); }
UserController { @GetMapping("") public List<UserVO> list() { List<UserVO> result = new ArrayList<>(); result.add(new UserVO().setId(1).setUsername("yudaoyuanma")); result.add(new UserVO().setId(2).setUsername("woshiyutou")); result.add(new UserVO().setId(3).setUsername("chifanshuijiao")); return result; }  @GetMapping("") List<UserVO> list(); @GetMapping("/{id}") UserVO get(@PathVariable("id") Integer id); @GetMapping("/v2/{id}") UserVO get2(@PathVariable("id") Integer id); @PostMapping("") Integer add(UserAddDTO addDTO); @PutMapping("/{id}") Boolean update(@PathVariable("id") Integer id, UserUpdateDTO updateDTO); @DeleteMapping("/{id}") Boolean delete(@PathVariable("id") Integer id);  }