spring - SpringMVC getter setter best practice -


I've got the following code: I'm just on a POC with SpringMVC ...

  @RequestMapping (value = "/ getUser", method = RequestMethod.GET) @ResponseBody public user data (local environment, model model, user user) {logger.info ("getUser controller load ..."); Return userService.getById (user.getId ()); } @RequestMapping (value = "/ setUser", method = RequestMethod.GET) @ResponseBody Public Zero Data (Locale Locale, Model Model, User User) {logger.info ("setUser controller load ..."); UserService.addUser (user); }   

As you can see, it creates a problem because the method signatures are both the same. What is the best way to divide them because the annotation methods begin to get functionality rather than names, can there be anything called the method? What is the best practice method in Vasantmavisi to make Setter and Gestator Controller?

is not really the best practice, but this is what I have used:

For the method name - either set to list (for a list) or show (for one item)

The name of the method - update or creating is based on whether you are updating an item or creating a new item

the method Whatever the name, make sure that it is the @RequestMapping annotation It is said that REST-based mapped methods are considered to be a good practice - although considering the user, a controller controller will look like this @RequestMapping ("/ user") @controller public class UserController {@ RequestMapping (production = "text / html") public string list () {} @RequestMapping (value = "/ {ID}", generated = "text / html") public string show () {} @RequestMapping (method = RequestMethod .POST, produces = "text / public String Update (@Wild User User, Binding Binding Result, Model) {} @RequestMapping (value = "/ {ID}", method = RequestMethod.DELETE, output = "text / html") Delete public string (. .) {}}

Comments