@RequestMapping(value = "info", method = RequestMethod.POST) @ResponseBody public ResponseEntity<String> doGetUserInfo(HttpServletRequest request) throws Exception { User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal(); StringBuilder out = new StringBuilder(); out.append("{ \"user\" : "); out.append( String.format( "{ \"id\" : \"%s\" , \"realname\" : \"%s\" , \"username\" : \"%s\"}", user.getId(), user.getRealname(), user.getUsername())); out.append("}"); HttpHeaders headers = new HttpHeaders(); headers.set("Content-Type", "application/json"); return new ResponseEntity<String>(out.toString(), headers, HttpStatus.OK); }
@RequestMapping("add") public ModelAndView addForm(User userBean) { userBean.setEnabled(true); return new ModelAndView("user/form", "userBean", userBean); }
// ------------------------ // Binding public User createFormUser() { User user = new User(); user.setEnabled(true); user.setRole(Role.ROLE_USER); return user; }