@RequestMapping(value={"/",""},method=RequestMethod.PUT) @ResponseBody public RestWrapper insert(@ModelAttribute("userroles") @Valid UserRoles userRoles,BindingResult bindingResult,Principal principal){
  RestWrapper restWrapper=null;
  if (bindingResult.hasErrors()) {
    BindingResultError bindingResultError=new BindingResultError();
    return bindingResultError.errorMessage(bindingResult);
  }
  try {
    com.wipro.ats.bdre.md.dao.jpa.UserRoles jpaUserRoles=new com.wipro.ats.bdre.md.dao.jpa.UserRoles();
    jpaUserRoles.setUserRoleId(userRoles.getUserRoleId());
    jpaUserRoles.setRole(userRoles.getRole());
    Users users=new Users();
    users.setUsername(userRoles.getUsername());
    jpaUserRoles.setUsers(users);
    Integer userRolesId=userRolesDAO.insert(jpaUserRoles);
    userRoles.setUserRoleId(userRolesId);
    restWrapper=new RestWrapper(userRoles,RestWrapper.OK);
    LOGGER.info("Record with ID:" + userRoles.getUserRoleId() + " inserted in UserRoles by User:"+ principal.getName()+ userRoles);
  }
 catch (  Exception e) {
    LOGGER.error(e);
    restWrapper=new RestWrapper(e.getMessage(),RestWrapper.ERROR);
  }
  return restWrapper;
}

@ RequestMapping ( value = { "/" , "" } , method = RequestMethod . PUT ) @ ResponseBody public RestWrapper insert ( @ ModelAttribute ( "userroles" ) @ Valid UserRoles userRoles , BindingResult bindingResult , Principal principal ) { RestWrapper restWrapper = null ; if ( bindingResult . hasErrors ( ) ) { BindingResultError bindingResultError = new BindingResultError ( ) ; return bindingResultError . errorMessage ( bindingResult ) ; } try { com . wipro . ats . bdre . md . dao . jpa . UserRoles jpaUserRoles = new com . wipro . ats . bdre . md . dao . jpa . UserRoles ( ) ; jpaUserRoles . setUserRoleId ( userRoles . getUserRoleId ( ) ) ; jpaUserRoles . setRole ( userRoles . getRole ( ) ) ; Users users = new Users ( ) ; users . setUsername ( userRoles . getUsername ( ) ) ; jpaUserRoles . setUsers ( users ) ; Integer userRolesId = userRolesDAO . insert ( jpaUserRoles ) ; userRoles . setUserRoleId ( userRolesId ) ; restWrapper = new RestWrapper ( userRoles , RestWrapper . OK ) ; LOGGER . info ( "Record with ID:" + userRoles . getUserRoleId ( ) + " inserted in UserRoles by User:" + principal . getName ( ) + userRoles ) ; } catch ( Exception e ) { LOGGER . error ( e ) ; restWrapper = new RestWrapper ( e . getMessage ( ) , RestWrapper . ERROR ) ; } return restWrapper ; }
this method calls proc insertuserroles and adds a record in userroles table . it also validates the values passed .
