0

当我打印 studentForm 时,值是正确的,但信息为空。这有什么问题?

StudentForm studentForm = (StudentForm) form;
StudentStructure info = studentForm.getStudent();
StudentDaoFactory.getDaoFactory().getStudentDao().insert(info);

这是学生表格

package com.getcare.crud.web;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import net.sf.hibernate.mapping.Collection;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;

import com.getcare.crud.remote.StudentContactInfoStructure;
import com.getcare.crud.remote.StudentStructure;

public class StudentForm extends ActionForm{

    private static final long serialVersionUID = 1L;

    private StudentStructure student = new StudentStructure();
    private StudentContactInfoStructure studentContact = new StudentContactInfoStructure();


    public void setId(int id){
        this.student.setId(id);
        this.studentContact.setId(id);
    }




    public void setStudentid(int studentid) {
        studentContact.setId(student.getId());
        studentContact.setStudentid(studentid);
    }





    public void setFirstName(String firstName) {
        student.setFirstName(firstName);
    }





    public void setMiddleName(String middleName) {
        student.setMiddleName(middleName);
    }




    public void setLastName(String lastName) {
        student.setLastName(lastName);
    }




    public void setGender(String gender) {
        student.setGender(gender);
    }





    public void setBirthdate(String birthdate) {
        student.setBirthdate(birthdate);
    }





    public void setCourse(String course) {
        student.setCourse(course);
    }




    public Integer getPhone(){
        return studentContact.getPhone();
    }
    public void setPhone(Integer phone){
        student.setPhone(phone);
        studentContact.setPhone(phone);
    }



    public String getAddress(){
        return studentContact.getAddress();
    }
    public void setAddress(String address){
        studentContact.setAddress(address);
        student.setAddress(address);
    }




    public void setClassCode(Integer classCode) {
        student.setClassCode(classCode);
    }




    public void setStudents(ArrayList students) {
        student.setStudents(students);
    }





    public void setStudentContacts(ArrayList studentContacts) {
        studentContact.setStudentContacts(studentContacts);
    }




    public void setStudentContact(StudentContactInfoStructure studentContact) {
        studentContact.setContact(studentContact);
    }



    public void setStudent(StudentStructure student) {
        student.setStudent(student);
    }




    public int getId() {
        return student.getId();
    }
    public Integer getStudentid() {
        return studentContact.getId();
    }
    public String getFirstName() {
        return student.getFirstName();
    }
    public String getMiddleName() {
        return student.getMiddleName();
    }   
    public String getLastName() {
        return student.getLastName();
    }
    public String getGender() {
        return student.getGender();
    }
    public String getBirthdate() {
        return student.getBirthdate();
    }
    public String getCourse() {
        return student.getCourse();
    }
    public Integer getClassCode(){
        return student.getClassCode();
    }
    public ArrayList getStudents() {
        return student.getStudents();
    }
    public ArrayList getStudentContacts() {
        return studentContact.getStudentContacts();
    }
    public StudentContactInfoStructure getStudentContact() {
        return studentContact.getContact();
    }   
    public StudentStructure getStudent() {
        return student.getStudent();
    }


    @Override
    public void reset(ActionMapping mapping, HttpServletRequest request) {
        super.reset(mapping, request);
//      setId(0);
        setFirstName(null);
        setLastName(null);
        setMiddleName(null);
        setGender(null);
        setBirthdate(null);
        setCourse(null);
        setPhone(null);
        setAddress(null);
        setClassCode(null);
    }




}

然后是 StudentStructure

package com.getcare.crud.remote;

import java.io.Serializable;
import java.util.ArrayList;

import com.getcare.remote.Structure;

/**
 * 
 * @author clemjon
 *
 * @hibernate.class table="student"
 */

public class StudentStructure extends Structure implements Serializable{

    private Integer id;
    private Integer phone,classCode;
    private String firstName, middleName, lastName, gender, birthdate, course,address;
    private ArrayList students;
    private StudentStructure student = new StudentStructure();

    public StudentStructure getStudent() {
        return student;
    }

    public void setStudent(StudentStructure student) {
        this.student = student;
    }

    public ArrayList getStudents() {
        return students;
    }
    public void setStudents(ArrayList arrayList) {
        this.students = arrayList;
    }
    /**
     * @hibernate.id generator-class="sequence"
     * @hibernate.generator-param name="sequence" value="student_id_seq"
     */


    public Integer getId() {
        return id;
    }
    public void setId(Integer id) {
        this.id = id;
    }




    /**
     * @hibernate.property
     *
     */

    public String getFirstName() {
        return firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }




    /**
     * @hibernate.property
     * 
     */


    public String getMiddleName() {
        return middleName;
    }
    public void setMiddleName(String middleName) {
        this.middleName = middleName;
    }




    /**
     * @hibernate.property
     * 
     */

    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }




    /**
     * @hibernate.property
     * 
     */

    public String getGender() {
        return gender;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }




    /**
     * @hibernate.property
     * 
     */

    public String getBirthdate() {
        return birthdate;
    }

    public void setBirthdate(String birthdate) {
        this.birthdate = birthdate;
    }



    /**
     * @hibernate.property
     * 
     */

    public String getCourse() {
        return course;
    }

    public void setCourse(String course) {
        this.course = course;
    }



//  /**
//   * @hibernate.property
//   * 
//   */

    public Integer getPhone(){
        return phone;
    }

    public void setPhone(Integer phone){
        this.phone = phone;
//      this.contact.setPhone(phone);
    }




//  /**
//   * @hibernate.property
//   * 
//   */

    public String getAddress(){
        return address;
    }

    public void setAddress(String address){
        this.address = address;
//      contact.setAddress(address);
    }


    /**
     * @hibernate.property
     * 
     */

    public Integer getClassCode(){
        return classCode;
    }

    public void setClassCode(Integer classCode) {
        this.classCode = classCode;
    }



//  public StudentStructure safeClone() {
//      StudentStructure newInstance = new StudentStructure();
//      newInstance.copy(StudentStructure.class, this);
//      return newInstance;
//  }


}

和 StudentContactInfoStructure

package com.getcare.crud.remote;

import java.io.Serializable;
import java.util.ArrayList;

import com.getcare.remote.Structure;

/**
 * 
 * @author clemjon
 *
 * @hibernate.class table="studentcontactinfo"
 */

public class StudentContactInfoStructure {
    private Integer id, phone,studentid;
    private String address;
    private ArrayList studentContacts;
    private StudentContactInfoStructure contact = new StudentContactInfoStructure();

    public StudentContactInfoStructure getContact() {
        return contact;
    }
    public void setContact(StudentContactInfoStructure contact) {
        this.contact = contact;
    }
    public ArrayList getStudentContacts() {
        return studentContacts;
    }
    public void setStudentContacts(ArrayList studentContact) {
        this.studentContacts = studentContact;
    }

    /**
     * @hibernate.id generator-class="sequence"
     * @hibernate.generator-param name="sequence" value="studentcontact_id_seq"
     */


    public Integer getId() {
        return id;
    }
    public void setId(Integer id) {
        this.id = id;
    }



    /**
     * @hibernate.property
     * 
     */

    public Integer getPhone(){
        return phone;
    }

    public void setPhone(Integer phone){
        this.phone = phone;
    }




    /**
     * @hibernate.property
     * 
     */

    public String getAddress(){
        return address;
    }

    public void setAddress(String address){
        this.address = address;
    }



    /**
     * @hibernate.property
     * 
     */

    public Integer getStudentid(){
        return studentid;
    }

    public void setStudentid(Integer studentid){
        this.studentid = studentid;
    }


}

我不知道我会修改什么。:D 谢谢

4

1 回答 1

0

因为,studentForm.getStudent()返回null。

于 2013-10-23T06:06:37.250 回答