两个表:

  Customer 顾客表

create table  if not exists customer(
customer_id int primary key auto_increment,
first_name varchar(20),
last_name varchar(20),
company varchar(20),
address varchar(20),
city varchar(20),
state int ,
country varchar(20),
postal_code varchar(20),
phone varchar(11),
fax varchar(11),
email varchar(20),
support_repld int

);

Invoice 发票表
create table if not exists invoice(
invoice_id int primary key auto_increment,
invoice_date date,
billing_address varchar(20),
billing_city varchar(20),
billing_state int ,
billing_country varchar(20),
billing_postalCode varchar(20),
total decimal(10,2),
customer_id int references coustomer(customer_id)
);

1、根据两个表合理创建
2、三个类能正确创建出来,并建立友好关系

要求:1、依据发票的id查询发票的信息,请配置映射,要求Invoice与BillingInfo的实例都能正确创建出来。
   2、假定要依据客户的id,查询出客户及其关联的发票信息,请配置映射。

实体类

  Customer

package com.oukele.entity_invoice;

import java.util.List;

public class Customer {
    private int customerId;
    private String firstName;
    private String lastName;
    private String company;
    private String address;
    private String city;
    private int state;
    private String country;
    private String postalCode;
    private String phone;
    private String fax;
    private String email;
    private int supportRepId;
    private List<Invoice> invoices;

    public int getCustomerId() {
        return customerId;
    }

    public void setCustomerId(int customerId) {
        this.customerId = customerId;
    }

    public String getFirstName() {
        return firstName;
    }

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

    public String getLastName() {
        return lastName;
    }

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

    public String getCompany() {
        return company;
    }

    public void setCompany(String company) {
        this.company = company;
    }

    public String getAddress() {
        return address;
    }

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

    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    public int getState() {
        return state;
    }

    public void setState(int state) {
        this.state = state;
    }

    public String getCountry() {
        return country;
    }

    public void setCountry(String country) {
        this.country = country;
    }

    public String getPostalCode() {
        return postalCode;
    }

    public void setPostalCode(String postalCode) {
        this.postalCode = postalCode;
    }

    public String getPhone() {
        return phone;
    }

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

    public String getFax() {
        return fax;
    }

    public void setFax(String fax) {
        this.fax = fax;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public int getSupportRepId() {
        return supportRepId;
    }

    public void setSupportRepId(int supportRepId) {
        this.supportRepId = supportRepId;
    }

    public List<Invoice> getInvoices() {
        return invoices;
    }

    public void setInvoices(List<Invoice> invoices) {
        this.invoices = invoices;
    }

    @Override
    public String toString() {
        return "Customer{" +
                "customerId=" + customerId +
                ", firstName='" + firstName + '\'' +
                ", lastName='" + lastName + '\'' +
                ", company='" + company + '\'' +
                ", address='" + address + '\'' +
                ", city='" + city + '\'' +
                ", state=" + state +
                ", country='" + country + '\'' +
                ", postalCode='" + postalCode + '\'' +
                ", phone='" + phone + '\'' +
                ", fax='" + fax + '\'' +
                ", email='" + email + '\'' +
                ", supportRepId=" + supportRepId +
                ", invoices=" + invoices +
                '}';
    }
}
View Code

相关文章: