@Test public void userByFullname() throws Exception { mockMvc.perform(get("/user?fullname={fullname}", "Samed Düzçay")) .andExpect(status().isOk()) .andExpect( content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) .andExpect(jsonPath("$.username", is("samed"))) .andExpect(jsonPath("$.fullname", is("Samed Düzçay"))) .andExpect(jsonPath("$.email", is("smddzcy@gmail.com"))); verify(repo, times(1)).findByFullname("Samed Düzçay"); verifyNoMoreInteractions(repo); }
@RequestMapping(method = RequestMethod.GET, value = "", params = "fullname", produces = MediaType.APPLICATION_JSON_UTF8_VALUE) public @ResponseBody User userByFullname(@RequestParam("fullname") String fullname) { return repository.findByFullname(fullname); }
UserController { @RequestMapping(method = RequestMethod.GET, value = "", params = "fullname", produces = MediaType.APPLICATION_JSON_UTF8_VALUE) public @ResponseBody User userByFullname(@RequestParam("fullname") String fullname) { return repository.findByFullname(fullname); } }
UserController { @RequestMapping(method = RequestMethod.GET, value = "", params = "fullname", produces = MediaType.APPLICATION_JSON_UTF8_VALUE) public @ResponseBody User userByFullname(@RequestParam("fullname") String fullname) { return repository.findByFullname(fullname); } @Autowired  UserController(UserRepository repository); }
UserController { @RequestMapping(method = RequestMethod.GET, value = "", params = "fullname", produces = MediaType.APPLICATION_JSON_UTF8_VALUE) public @ResponseBody User userByFullname(@RequestParam("fullname") String fullname) { return repository.findByFullname(fullname); } @Autowired  UserController(UserRepository repository); @RequestMapping(method = RequestMethod.GET, value = "", params = "username", produces = MediaType.APPLICATION_JSON_UTF8_VALUE) @ResponseBody User userByUsername(@RequestParam("username") String username); @RequestMapping(method = RequestMethod.GET, value = "", params = "fullname", produces = MediaType.APPLICATION_JSON_UTF8_VALUE) @ResponseBody User userByFullname(@RequestParam("fullname") String fullname); @RequestMapping(method = RequestMethod.GET, value = "/{id}", produces = MediaType.APPLICATION_JSON_UTF8_VALUE) @ResponseBody User userById(@PathVariable("id") long id); @RequestMapping(method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) @ResponseBody List<User> user(); @RequestMapping(method = RequestMethod.PUT, value = "/{id}", produces = MediaType.APPLICATION_JSON_UTF8_VALUE) @ResponseBody User update(@PathVariable("id") long id,
                @RequestParam MultiValueMap<String, String> params); @RequestMapping(method = RequestMethod.PUT, value = "", params = "username", produces = MediaType.APPLICATION_JSON_UTF8_VALUE) @ResponseBody User updateByUsername(@RequestParam MultiValueMap<String, String> params); @RequestMapping(method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) @ResponseBody User insertData(@ModelAttribute("insertUser") @Valid User user,
                    BindingResult result); @RequestMapping(method = RequestMethod.DELETE, value = "/{id}", produces = MediaType.APPLICATION_JSON_UTF8_VALUE) @ResponseBody ResponseEntity<Void> deleteUserById(@PathVariable("id") long id); @RequestMapping(method = RequestMethod.DELETE, value = "", params = "username", produces = MediaType.APPLICATION_JSON_UTF8_VALUE) @ResponseBody ResponseEntity<Void> deleteUserByUsername(@RequestParam("username")
                                                  String username); @ExceptionHandler(CustomException.class) ResponseEntity<ErrorResponse> exceptionHandler(CustomException ex); }
UserController { @RequestMapping(method = RequestMethod.GET, value = "", params = "fullname", produces = MediaType.APPLICATION_JSON_UTF8_VALUE) public @ResponseBody User userByFullname(@RequestParam("fullname") String fullname) { return repository.findByFullname(fullname); } @Autowired  UserController(UserRepository repository); @RequestMapping(method = RequestMethod.GET, value = "", params = "username", produces = MediaType.APPLICATION_JSON_UTF8_VALUE) @ResponseBody User userByUsername(@RequestParam("username") String username); @RequestMapping(method = RequestMethod.GET, value = "", params = "fullname", produces = MediaType.APPLICATION_JSON_UTF8_VALUE) @ResponseBody User userByFullname(@RequestParam("fullname") String fullname); @RequestMapping(method = RequestMethod.GET, value = "/{id}", produces = MediaType.APPLICATION_JSON_UTF8_VALUE) @ResponseBody User userById(@PathVariable("id") long id); @RequestMapping(method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) @ResponseBody List<User> user(); @RequestMapping(method = RequestMethod.PUT, value = "/{id}", produces = MediaType.APPLICATION_JSON_UTF8_VALUE) @ResponseBody User update(@PathVariable("id") long id,
                @RequestParam MultiValueMap<String, String> params); @RequestMapping(method = RequestMethod.PUT, value = "", params = "username", produces = MediaType.APPLICATION_JSON_UTF8_VALUE) @ResponseBody User updateByUsername(@RequestParam MultiValueMap<String, String> params); @RequestMapping(method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) @ResponseBody User insertData(@ModelAttribute("insertUser") @Valid User user,
                    BindingResult result); @RequestMapping(method = RequestMethod.DELETE, value = "/{id}", produces = MediaType.APPLICATION_JSON_UTF8_VALUE) @ResponseBody ResponseEntity<Void> deleteUserById(@PathVariable("id") long id); @RequestMapping(method = RequestMethod.DELETE, value = "", params = "username", produces = MediaType.APPLICATION_JSON_UTF8_VALUE) @ResponseBody ResponseEntity<Void> deleteUserByUsername(@RequestParam("username")
                                                  String username); @ExceptionHandler(CustomException.class) ResponseEntity<ErrorResponse> exceptionHandler(CustomException ex);  }