技术开发 频道

用Java+Flex编写一个简单而强大的RIA

  清单 1. Java Contact 类

package bcit.contacts;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

@Entity
@Table(name
="contact")
@NamedQueries( {
    @NamedQuery(name
= "contact.findAll", query = "from Contact"),
    @NamedQuery(name
= "contact.getById", query =
        
"select c from Contact c where c.id = :id")
} )
public class Contact {

    
private static final long serialVersionUID = 123456789L;

    
public Contact() {
        firstName
= "N/A";
        lastName
= "N/A";
        emailAddress
= "N/A";
        phoneNumber
= "N/A";
    }

    
public Contact(String first, String last, String email, String number) {
        firstName
= first;
        lastName
= last;
        emailAddress
= email;
        phoneNumber
= number;
    }

    @Id
    @GeneratedValue(strategy
= GenerationType.AUTO)
    @Column(name
= "id", nullable = false, updatable=false)
    
private long id;

    @Column(name
= "lastName", nullable = false, unique = false)
    
private String lastName;

    @Column(name
= "firstName", nullable = false, unique = false)
    
private String firstName;

    @Column(name
= "emailAddress", nullable = false, unique = false)
    
private String emailAddress;

    @Column(name
= "phoneNumber", nullable = false, unique = false)
    
private String phoneNumber;

    
public void setPhoneNumber(String number) { phoneNumber = number; }

    
public String getPhoneNumber() { return phoneNumber; }

    
public String getEmailAddress() { return emailAddress; }

    
public void setEmailAddress(String address) { emailAddress = address; }

    
public String getFirstName() { return firstName; }

    
public void setFirstName(String first) { firstName = first; }

    
public String getLastName() { return lastName; }

    
public void setLastName(String last) { lastName = last; }

    
public long getId() { return id; }

    
public void setId(long newId) { id = newId; }

    @Override
    
public String toString() {
        return id
+ " " + firstName + " " + lastName + " " + emailAddress
            
+ " " + phoneNumber;
    }
}


0
相关文章