4.编写数据表对应的三个javaBean
- 编写javaBean,名字分别为Goods,Type,Recommend,其中
因为goods表里面有一个type_id的外键,所以在实体类中使用Type类型的对象来表示。同样的在Recommend表里面也有一个Goods类型的对象。代码如下所示:
Goods:
package com.sikiedu.model;
public class Goods {
private int id;
private String name;
private String cover;
private String image1;
private String image2;
private float price;
private String intro;
private int stock;
private Type type;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getCover() {
return cover;
}
public void setCover(String cover) {
this.cover = cover;
}
public String getImage1() {
return image1;
}
public void setImage1(String image1) {
this.image1 = image1;
}
public String getImage2() {
return image2;
}
public void setImage2(String image2) {
this.image2 = image2;
}
public float getPrice() {
return price;
}
public void setPrice(float price) {
this.price = price;
}
public String getIntro() {
return intro;
}
public void setIntro(String intro) {
this.intro = intro;
}
public int getStock() {
return stock;
}
public void setStock(int stock) {
this.stock = stock;
}
public Type getType() {
return type;
}
public void setType(Type type) {
this.type = type;
}
public Goods(int id, String name, String cover, String image1,
String image2, float price, String intro, int stock, Type type) {
super();
this.id = id;
this.name = name;
this.cover = cover;
this.image1 = image1;
this.image2 = image2;
this.price = price;
this.intro = intro;
this.stock = stock;
this.type = type;
}
public Goods() {
super();
}
}
Type:
package com.sikiedu.model;
public class Type {
private int id;
private String name;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Type(int id, String name) {
super();
this.id = id;
this.name = name;
}
public Type() {
super();
}
}
Recommend:
package com.sikiedu.model;
public class Recommend {
private int id;
private int type;//1条幅,2热销,3新品
private Goods goods;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getType() {
return type;
}
public void setType(int type) {
this.type = type;
}
public Goods getGoods() {
return goods;
}
public void setGoods(Goods goods) {
this.goods = goods;
}
public Recommend(int id, int type, Goods goods) {
super();
this.id = id;
this.type = type;
this.goods = goods;
}
public Recommend() {
super();
}
}