2013-09-11 27 views
0
$.ajax({ 
         url:'${pageContext.request.contextPath}/backend/system/userRelative/add', 
         type: 'POST', 
         data: { 
          id:$("#id").val(), 
          cardNo:userCardNoAdd.val(), 
          userName:userNameAdd.val(), 
          companyName:companyNameAdd.val(), 
          departmentName:departmentNameAdd.val(), 
          userRelatives.relativeName:relativeNameAdd.val(), 
          userRelatives.relativeType:relativeTypeAdd.val(), 
          userRelatives.relativeCardNo:relativeCardNoAdd.val()}, 
         error: function(XMLHttpRequest, textStatus, errorThrown){alert('error' + textStatus + "/" + errorThrown);}, 
         success: function(data){ 
          if(data=='success') { 
           alert('success'); 
           $("#userRelativeDIV").dialog("close"); 
          } else { 
           alert('fail'); 
          } 
         } 
        }); 

* User和UserRelative具有一对多的关系;现在我想保存一个实体用户;但是我有一个问题;如何使用jquery.ajax发送实体用户对Spring控制器;我怎样才能把价值成通过jquery.ajax设置*我如何通过jquery.ajax将值设置为<UserRelative>

public class User implements java.io.Serializable { 
private long id; 
private String userName; 
private Set<UserRelative> userRelatives = new HashSet<UserRelative>(0); 
......} 

公共类UserRelative实现java.io.Serializable {

private long id; 
private User user; 
private String relativeName; 
private String relativeType; 
private String cardNo; 
...} 

回答

0

我不是专家,但如果我是你,我只会使用AJAX发布对应于用户属性的值。并在Controller内部构建User实体并保存到Model中。

相关问题