@RequestMapping(value="/save") @ResponseBody public String create(String email, String name) { try { User user = new User(email, name); _userDao.save(user); } catch(Exception ex) { return ex.getMessage(); } return "User succesfully saved!"; }
/** * /create --> Create a new user and save it in the database. * * @param email User's email * @param name User's name * @return A string describing if the user is successfully created or not. */ @RequestMapping("/create") @ResponseBody public String create(String email, String name) { User user = null; try { user = new User(email, name); userDao.save(user); } catch (Exception ex) { return "Error creating the user: " + ex.toString(); } return "User succesfully created! (id = " + user.getId() + ")"; }
/** * /update --> Update the email and the name for the user in the database * having the passed id. * * @param id The id for the user to update. * @param email The new email. * @param name The new name. * @return A string describing if the user is successfully updated or not. */ @RequestMapping("/update") @ResponseBody public String updateUser(long id, String email, String name) { try { User user = userDao.findOne(id); user.setEmail(email); user.setName(name); userDao.save(user); } catch (Exception ex) { return "Error updating the user: " + ex.toString(); } return "User successfully updated!"; }