问题介绍:填写一个文档,这个文档有不同的字段,使用form提交给相应的action;但是其中一个字段是一个需要填写的表格,用什么方式提交呢?文档和表格都对应着一个model类。
求大牛指点~~~

解决方案 »

  1.   

    假设文档类是class w 表格类是class b
    action中定义一个w类型的属性就可以了
    然后页面上表单字段的name 属性就= w.xxx
    表格的字段就name=w.b.xxx就行了
    前提是你的类w要有一个b类型的属性
      

  2.   

    建两张表,主从表一对一映射,然后在表单那里的表格字段name属性写主表.从表.属性  注入
      

  3.   

    把这个表格定义成一个list对象,这个list是form中的一个属性
      

  4.   

    <s:set name="empStatus"
    value="# {'':'--请选择--','1':'临时','2':'试用','3':'在职','4':'停职','5':'离职'}"></s:set> <s:form action="/hrEmploy_doAdd.do?param=add" method="post"
    enctype="multipart/form-data" id="myform" theme="simple">
    <s:hidden id="jihua" theme="simple"></s:hidden>
    <s:hidden id="xingbie" theme="simple"></s:hidden>
    <s:hidden id="images" theme="simple" name="hrEmploy.default03"></s:hidden>
    <table style="width: 1000px" border="0" cellspacing="0"
    cellpadding="0">
    <tr>
    <td colspan="6">
    <div class="select_title">
    <ul>
    <li>
    <b>员工信息新增</b>
    </li>
    </ul>
    </div>
    </td>
    </tr>
    <tr>
    <td class="right" width="10%">
    <font style="color: red; margin-right: 2px;">*</font>系统编号:
    </td>
    <td class="left">
    <label>
    <s:textfield name="hrEmploy.employId" theme="simple"
    maxlength="20" readonly="true"
    cssClass="{required:true,messages:{required:'系统编号不能为空!'}}">
    </s:textfield>
    </label>
    </td> <td class="right">
    工 号:
    </td>
    <td class="left">
    <label>
    <s:textfield name="hrEmploy.workNo" theme="simple"
    maxlength="20"></s:textfield>
    </label>
    </td>
    <TD rowspan="7">
    <div id="tupian" style="display: none">
    <img src="" width="200px" height="145px" id="image" />
    </div>
    <div id="uploadFile" style="width: 220; height: 145">
    <span id="show"></span>
    </div>
    &nbsp;
    </TD>
    </tr>
    <tr>
    <td class="right">
    简历编号:
    </td>
    <td class="left">
    <label>
    <s:textfield name="hrEmploy.resumeId" id="jianli"
    theme="simple" maxlength="20" onfocus="winOpen()"></s:textfield>
    </label>
    </td> <td class="right">
    <font style="color: red; margin-right: 2px;">*</font>员工姓名:
    </td>
    <td class="left">
    <label>
    <s:textfield name="hrEmploy.fullName" theme="simple"
    maxlength="20" id="fullName"
    cssClass="{required:true,messages:{required:'员工姓名不能为空!'}}"></s:textfield>
    </label>
    </td> </tr>
    <tr>
    <td class="right" width="10%">
    <font style="color: red; margin-right: 2px;">*</font>性别:
    </td>
    <td class="left">
    <label>
    <s:radio list="# {0:'男',1:'女'}" theme="simple" id="sex"
    name="hrEmploy.sex" listKey="key" listValue="value" value="0"></s:radio>
    </label>
    </td> <td class="right">
    <font style="color: red; margin-right: 2px;">*</font>所属机构:
    </td>
    <td class="left">
    <label>
    <s:select list="#request.oqr" listKey="key" disabled="true"
    listValue="value.organName" headerKey="" headerValue="--请选择--"
    cssStyle="width:133px" theme="simple" name="hrEmploy.organId"
    cssClass="{required:true}"></s:select>
    <s:hidden name="hrEmploy.organId" />
    </label>
    </td>
    </tr>
    <tr>
    <td class="right">
    <font style="color: red; margin-right: 2px;">*</font>所属部门:
    </td>
    <td class="left">
    <label>
    <s:select list="#request.dqr" listKey="key"
    name="hrEmploy.deptId" listValue="value.deptName" headerKey=""
    headerValue="--请选择--" theme="simple"
    cssClass="{required:true}" cssStyle="width:132px"></s:select>
    </label>
    &nbsp;
    </td>
    <td class="right">
    <font style="color: red; margin-right: 2px;">*</font>员工状态:
    </td>
    <td class="left">
    <label>
    <s:select name="hrEmploy.status" list="#empStatus"
    listKey="key" cssStyle=" width:132 " listValue="value"
    theme="simple"
    cssClass="{required:true,messages:{required:'员工状态不能为空!'}}">
    </s:select>
    </label>
    </td> </tr>
    <tr> <td class="right">
    岗位:
    </td>
    <td class="left">
    <label>
    <s:hidden id="hrEmploy.postId" name="hrEmploy.postId" />
    <s:textfield id="hrEmploy.postId1"
    value="%{#request.dqr2[hrEmploy.postId].postName}"
    theme="simple" onclick="winOpen5()" maxlength="20"></s:textfield>
    </label>
    </td>
    <td class="right">
    岗级:
    </td>
    <td class="left">
    <label> <s:hidden id="hrEmploy.postGrade" name="hrEmploy.postGrade" />
    <s:textfield id="hrEmploy.postGrade1"
    value="%{#request.dqr3[hrEmploy.postGrade].postGradeName}"
    readonly="true" theme="simple" onclick="winOpen3()"
    maxlength="20"></s:textfield>
    </label>
    </td> </tr> <tr>
    <td class="right">
    薪等:
    </td>
    <td class="left">
    <label> 
    <s:hidden id="wagId" name="hrEmploy.payId" />
    <s:textfield id="wagName"
    onclick="winOpen4()" theme="simple" />
    </label>
    </td>
    <td class="right">
    薪级:
    </td>
    <td class="left">
    <label>
    <s:hidden id="wagId1" name="hrEmploy.payGrade" />
    <s:textfield  id="wagGrade"
    theme="simple" />
    </label>
    </td>
    </tr>
    <tr>
    <td class="right">
    是否为系统用户:
    </td>
    <td class="left">
    <label>
    <s:radio list="# {0:'是',1:'否'}" theme="simple"
    name="hrEmploy.isOperate" listKey="key" listValue="value"
    value="1"></s:radio>
    </label>
    </td> <td class="right">
    图片:
    </td>
    <td class="left">
    <s:file name="upload" onchange="show()"  theme="simple" 
    cssStyle="width:195px" />
    </td>
    </tr>
    <tr>
    <td class="right">
    备注:
    </td>
    <td class="left" colspan="5">
    <label>
    <s:textarea name="hrEmploy.res" theme="simple" cols="80"
    rows="5"
    cssClass="{maxlength:25,messages:{minlength:'备注长度不能大于25位数!'}}"
    cssStyle="width:445px"></s:textarea>
    &nbsp;
    <span style="color: red">请输入25个字符以内的数据</span>
    </label>
    </td>
    </tr> </table>
    <div align="center" style="margin-right: 80px;">
    <s:submit value="确定" id="tijiao" theme="simple" cssClass="sure"></s:submit>
    <s:reset value="重置" theme="simple" cssClass="sure"></s:reset> <input type="button" value="返回" class="sure"
    onclick="javascript:history.go(-1)" /> </div>
    </s:form>
      

  5.   

    package com.daoyuan.common.bean;import java.util.Date;
    import java.util.HashSet;
    import java.util.Set;import javax.persistence.CascadeType;
    import javax.persistence.Column;
    import javax.persistence.Entity;
    import javax.persistence.FetchType;
    import javax.persistence.Id;
    import javax.persistence.OneToMany;
    import javax.persistence.Table;/**
     * HrEmploy entity. @author MyEclipse Persistence Tools
     */
    @Entity
    @Table(name = "Hr_Employ")
    public class HrEmploy implements java.io.Serializable { // Fields private String employId;
    private String workNo;
    private String fullName;
    private Integer sex;
    private String organId;
    private String deptId;
    private String postId;
    private String postGrade;
    private String payId;
    private String payGrade;
    private String resumeId;
    private Integer status;
    private Integer isOperate;
    private String creater;
    private Date createDate;
    private String res;
    private String default01;
    private String default02;
    private String default03;
    private String default04;
    private String default05;
    private Set<PmWcrunEmploy> pmWcrunEmploies = new HashSet<PmWcrunEmploy>(0); // Constructors /** default constructor */
    public HrEmploy() {
    } /** minimal constructor */
    public HrEmploy(String employId) {
    this.employId = employId;
    } /** full constructor */
    public HrEmploy(String employId, String workNo, String fullName,
    Integer sex, String organId, String deptId, String postId,
    String postGrade, String payId, String payGrade, String resumeId,
    Integer status, Integer isOperate, String creater,
    Date createDate, String res, String default01,
    String default02, String default03, String default04,
    String default05, Set<PmWcrunEmploy> pmWcrunEmploies) {
    this.employId = employId;
    this.workNo = workNo;
    this.fullName = fullName;
    this.sex = sex;
    this.organId = organId;
    this.deptId = deptId;
    this.postId = postId;
    this.postGrade = postGrade;
    this.payId = payId;
    this.payGrade = payGrade;
    this.resumeId = resumeId;
    this.status = status;
    this.isOperate = isOperate;
    this.creater = creater;
    this.createDate = createDate;
    this.res = res;
    this.default01 = default01;
    this.default02 = default02;
    this.default03 = default03;
    this.default04 = default04;
    this.default05 = default05;
    this.pmWcrunEmploies = pmWcrunEmploies;
    } // Property accessors
    @Id
    @Column(name = "EmployID", unique = true, nullable = false, length = 20)
    public String getEmployId() {
    return this.employId;
    } public void setEmployId(String employId) {
    this.employId = employId;
    } @Column(name = "WorkNo", length = 20)
    public String getWorkNo() {
    return this.workNo;
    } public void setWorkNo(String workNo) {
    this.workNo = workNo;
    } @Column(name = "FullName", length = 20)
    public String getFullName() {
    return this.fullName;
    } public void setFullName(String fullName) {
    this.fullName = fullName;
    } @Column(name = "Sex")
    public Integer getSex() {
    return this.sex;
    } public void setSex(Integer sex) {
    this.sex = sex;
    } @Column(name = "OrganID", length = 20)
    public String getOrganId() {
    return this.organId;
    } public void setOrganId(String organId) {
    this.organId = organId;
    } @Column(name = "DeptID", length = 20)
    public String getDeptId() {
    return this.deptId;
    } public void setDeptId(String deptId) {
    this.deptId = deptId;
    } @Column(name = "PostID", length = 20)
    public String getPostId() {
    return this.postId;
    } public void setPostId(String postId) {
    this.postId = postId;
    } @Column(name = "PostGrade", length = 20)
    public String getPostGrade() {
    return this.postGrade;
    } public void setPostGrade(String postGrade) {
    this.postGrade = postGrade;
    } @Column(name = "PayID", length = 20)
    public String getPayId() {
    return this.payId;
    } public void setPayId(String payId) {
    this.payId = payId;
    } @Column(name = "PayGrade", length = 20)
    public String getPayGrade() {
    return this.payGrade;
    } public void setPayGrade(String payGrade) {
    this.payGrade = payGrade;
    } @Column(name = "ResumeID", length = 20)
    public String getResumeId() {
    return this.resumeId;
    } public void setResumeId(String resumeId) {
    this.resumeId = resumeId;
    } @Column(name = "Status")
    public Integer getStatus() {
    return this.status;
    } public void setStatus(Integer status) {
    this.status = status;
    } @Column(name = "IsOperate")
    public Integer getIsOperate() {
    return this.isOperate;
    } public void setIsOperate(Integer isOperate) {
    this.isOperate = isOperate;
    } @Column(name = "Creater", length = 20)
    public String getCreater() {
    return this.creater;
    } public void setCreater(String creater) {
    this.creater = creater;
    } @Column(name = "CreateDate", length = 23)
    public Date getCreateDate() {
    return this.createDate;
    } public void setCreateDate(Date createDate) {
    this.createDate = createDate;
    } @Column(name = "Res", length = 50)
    public String getRes() {
    return this.res;
    } public void setRes(String res) {
    this.res = res;
    } @Column(name = "Default01", length = 50)
    public String getDefault01() {
    return this.default01;
    } public void setDefault01(String default01) {
    this.default01 = default01;
    } @Column(name = "Default02", length = 50)
    public String getDefault02() {
    return this.default02;
    } public void setDefault02(String default02) {
    this.default02 = default02;
    } @Column(name = "Default03", length = 1000)
    public String getDefault03() {
    return this.default03;
    } public void setDefault03(String default03) {
    this.default03 = default03;
    } @Column(name = "Default04", length = 50)
    public String getDefault04() {
    return this.default04;
    } public void setDefault04(String default04) {
    this.default04 = default04;
    } @Column(name = "Default05", length = 50)
    public String getDefault05() {
    return this.default05;
    } public void setDefault05(String default05) {
    this.default05 = default05;
    } @OneToMany(cascade = CascadeType.ALL, mappedBy = "hrEmploy")
    public Set<PmWcrunEmploy> getPmWcrunEmploies() {
    return this.pmWcrunEmploies;
    } public void setPmWcrunEmploies(Set<PmWcrunEmploy> pmWcrunEmploies) {
    this.pmWcrunEmploies = pmWcrunEmploies;
    }}
      

  6.   

    @Controller("hrEmployAction")
    @Scope("prototype")
    public class HrEmployAction extends BaseAction { private static final long serialVersionUID = 1L; @Resource(name = "hrEmployServiceImpl")
    private HrEmployService hrEmployService; private HrEmploy hrEmploy = new HrEmploy(); public HrEmploy getHrEmploy() {
    return hrEmploy;
    } public void setHrEmploy(HrEmploy hrEmploy) {
    this.hrEmploy = hrEmploy;
    } private File upload; // 长传文本的控件的name属性 private String uploadContentType;
    private String uploadFileName; public File getUpload() {
    return upload;
    } public void setUpload(File upload) {
    this.upload = upload;
    } public String getUploadContentType() {
    return uploadContentType;
    } public void setUploadContentType(String uploadContentType) {
    this.uploadContentType = uploadContentType;
    } public String getUploadFileName() {
    return uploadFileName;
    } public void setUploadFileName(String uploadFileName) {
    this.uploadFileName = uploadFileName;
    } private String images; // 保存简历表的图片路径
    public String getImages() {
    return images;
    } public void setImages(String images) {
    this.images = images;
    } /**
     * 准备添加的时候绑定数据  * 
     * @return
     */
    public String doAdd() {
    try {
    if(getCurrentUser()!=null){
    String param = request.getParameter("param");
    if (param != null && "add".equals(param)) { // 执行添加功能
    String empId = getHrEmploy().getEmployId();
    String workNo = getHrEmploy().getWorkNo();
    if (empId == null || "".equals(empId)) {
    getHrEmploy().setEmployId(
    hrEmployService.getKeyId(PageTool.HR_EMPLOY));
    }
    if (workNo == null || "".equals(workNo)) {
    getHrEmploy().setWorkNo(getHrEmploy().getEmployId());
    }
    SysUserInfo userinfo = getCurrentUser();

    getHrEmploy().setCreater(userinfo.getUserId());
    // getHrEmploy().setCreater("1");
    getHrEmploy().setCreateDate(
    new Date(System.currentTimeMillis()));
    // 上传图片信息
    String timestamp = null;
    if (getUpload() != null) {
    String dstPath = ServletActionContext.getServletContext()
    .getRealPath("/upload/R");
    String str = "|.jpg|.gif|.bmp|.jpeg|.png";// 获得图片的输出格式 String hou = getUploadFileName().substring(
    getUploadFileName().lastIndexOf(".")).toLowerCase(); // 截取.后面的格式和str进行匹配
    if (str.indexOf(hou) != -1) {
    timestamp = java.util.UUID.randomUUID() + hou; // 在此要重命名图片文件
    dstPath += timestamp;
    copy(getUpload(), new File(dstPath));
    getHrEmploy().setDefault03("/upload/R" + timestamp);
    }
    }
    getHrEmploy().setOrganId(getCurrentUser().getOrganId());
    hrEmployService.ExecInsert(getHrEmploy());
    wrtOperateLog("Hr_Employ", "增加一条id为"
    + getHrEmploy().getEmployId() + "的数据");
    response.sendRedirect("hrEmploy_doQuery.do");
    return null;
    } else { // 添加之前绑定数据
    this.getDept(); // 获取部门
    this.getOrgan(); // 获取机构信息
    String pk=hrEmployService.getKeyId(PageTool.HR_EMPLOY);
    hrEmploy.setEmployId(pk);
    hrEmploy.setWorkNo(pk);
    hrEmploy.setOrganId(getCurrentUser().getOrganId());
    return GOADD;
    }
    }
    return ERROR;
    } catch (Exception e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    wrtExceptionLog(e);
    }
    return null;
    } /**
     * 绑定单个员工的基本信息  * 
     * @return
     */
    public String goInfo() {
    try {
    String empId = request.getParameter("empId");
    if (empId != null && !"".equals(empId)) { // 执行添加功能
    setHrEmploy(hrEmployService.find(HrEmploy.class, empId));
    this.getDept(); // 获取部门
    this.getOrgan(); // 获取机构信息
    getPostB();
    getHrPostGradeB();

    getWageLevel();

    String param = request.getParameter("param");
    if (param != null && "goInfo".equals(param)) {
    return GOINFO;
    }
    return GOEDIT;
    }
    throw new SystemException("参数类型不合法", "error");
    } catch (Exception e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    wrtExceptionLog(e);
    }
    return null;
    } /**
     * 删除员工基本信息
     * 
     * @return
     */
    public String doDelete() {
    try {
    String empId = request.getParameter("empId");
    if (empId != null && !"".equals(empId)) {
    hrEmployService.ExecDelete(HrEmploy.class, empId);
    wrtOperateLog("Hr_Employ", "删除一条id为" + empId + "的数据");
    response.sendRedirect("hrEmploy_doQuery.do");
    return null;
    }
    throw new SystemException("参数类型不合法", "error");
    } catch (Exception e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    wrtExceptionLog(e);
    }
    return null;
    } public String doUpdate() {
    try {
    if (getHrEmploy() != null) {
    SysUserInfo userinfo = getCurrentUser();
    getHrEmploy().setCreater(userinfo.getUserId());
    // getHrEmploy().setCreater("1");
    getHrEmploy().setCreateDate(
    new Date(System.currentTimeMillis())); // 【创建时间】自动获取服务器的时间;
    // 上传图片信息
    String timestamp = null;
    if (getUpload() != null) {
    String dstPath = ServletActionContext.getServletContext()
    .getRealPath("/upload/R");
    String str = "|.jpg|.gif|.bmp|.jpeg|.png";// 获得图片的输出格式 String hou = getUploadFileName().substring(
    getUploadFileName().lastIndexOf(".")).toLowerCase(); // 截取.后面的格式和str进行匹配
    if (str.indexOf(hou) != -1) {
    timestamp = java.util.UUID.randomUUID() + hou; // 在此要重命名图片文件
    dstPath += timestamp;
    copy(getUpload(), new File(dstPath));
    getHrEmploy().setDefault03("/upload/R" + timestamp);
    }
    }
    getHrEmploy().setOrganId(getCurrentUser().getOrganId());
    hrEmployService.ExecUpdate(getHrEmploy());
    // 更新四个表的基本信息
    if (getUpload() != null) {
    hrEmployService.ExecUpdates(getHrEmploy().getEmployId(),
    getHrEmploy().getResumeId(), getHrEmploy()
    .getDefault03());
    }
    wrtOperateLog("Hr_Employ", "编辑一条id为"
    + getHrEmploy().getEmployId() + "的数据");
    response.sendRedirect("hrEmploy_doQuery.do");
    return null;
    }
    throw new SystemException("参数类型不合法", "error");
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    wrtExceptionLog(e);
    }
    return null;
    } /**
     * 查询出员工供系统用户添加选择 参数: isOperate =1 --可以为系统用户 default04 !=null
     * --default04为1时表示已经导入为系统用户
     * 
     */
    public String doQueryForUser() {
    String param = request.getParameter("param");
    try {
    this.getDept(); // 获取部门
    this.getOrgan(); // 获取机构信息
    LinkedHashMap<String, String> orderby = PageTool.setOrder(
    "createDate", "desc");
    ArrayList<String> propertyName = new ArrayList<String>();
    propertyName.add("organId");
    propertyName.add("deptId");
    propertyName.add("workNo");
    propertyName.add("fullName");
    propertyName.add("status");
    propertyName.add("isOperate");
    propertyName.add("default04");
    ArrayList<String> eql = new ArrayList();
    eql.add("=");
    eql.add("=");
    eql.add("like");
    eql.add("like");
    eql.add("=");
    eql.add("=");
    eql.add("=");
    PageTool.getResult(request, HrEmploy.class, hrEmployService,
    PageTool.INDEXEND, propertyName, eql, new Object[] {
    hrEmploy.getOrganId(), hrEmploy.getDeptId(),
    hrEmploy.getWorkNo(), hrEmploy.getFullName(),
    hrEmploy.getStatus(), 1, hrEmploy.getDefault04() },
    new String[] { "and", "and", "and", "and", "and", "and" },
    orderby);
    request.setAttribute("winOpen", param);
    return "forUser";
    } catch (Exception e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    wrtExceptionLog(e);
    }
    return null;
    }
    }