Database Reference
In-Depth Information
User Controller
The UserController class contains a method called edit , which takes several arguments including a User object. The
User object is converted from a JSON string and returns a User object. The response could be used to update the form
elements, but the values are already set within the form. In this case, the application uses the JSON response to let the
user know whether the update succeeded or not.
Listing 11-27. UserController Edit Method
@RequestMapping(value = "/user/edit", method = RequestMethod.PUT)
public @ResponseBody User edit (Model model, @ModelAttribute("currentuser") User currentuser ,
@RequestBody User jsonString ) {
try {
if (jsonString != null) {
currentuser.setFirstname(jsonString.getFirstname());
currentuser.setLastname(jsonString.getLastname());
currentuser = graphStoryInterface.getUserInterface().update (currentuser);
}
}
catch (Exception e) {
log.error(e);
}
return currentuser;
}
User Update Method
To complete the update, the UserController edit method calls the update method in UserImpl. Because the object
being passed into the update method simply modified the first and last name of the existing entity, the save method
can be used to update the properties in the graph.
Listing 11-28. The update Method in UserImpl
// UserImpl...
@Override
public User update (User user) throws Exception {
user = userRepository.save (user);
return user;
}
recall that each of the controllers and the front-end code make use of similar syntax. For this reason,
subsequent sections will not feature the controller and front-end code so as to focus on the Spring Data neo4j aspects of
the application. The controllers and front-end code will be referenced but not listed directly in the sections.
Note
 
 
Search WWH ::




Custom Search