对有一定ssh框架基础的同学有一定帮助
//当前的类是一个持久化类,是Category这个类。他映射了一个表category。所对应的 数据库是users
//这句:@Table(name =
"category", catalog = "users") 可以省略
@Entity
@Table(name = "category",
catalog = "users")
public class Category implements
java.io.Serializable {
private
static final long serialVersionUID = 3240281547213597385L;
private
Integer id;
private
String name;
private
String description;
private
Set<Product> products = new HashSet<Product>(0);
public
Category() {
}
public
Category(String name, String description, Set<Product> products) {
this.name
= name;
this.description = description;
this.products = products;
}
// 主键 :@Id 主键生成方式:strategy
= "increment"
//映射表中id这个字段,不能为空,并且是唯一的
@GenericGenerator(name =
"generator", strategy = "increment")
@Id
@GeneratedValue(generator =
"generator")
@Column(name = "id", unique = true,
nullable = false)
public
Integer getId() {
return
this.id;
}
public
void setId(Integer id) {
this.id = id;
}
//映射表中name这个字段 ,长度是500
@Column(name = "name", length = 500)
public
String getName() {
return
this.name;
}
public
void setName(String name) {
this.name = name;
}
//映射表中description这个字段 ,长度是500
@Column(name = "description", length
= 500)
public
String getDescription() {
return
this.description;
}
评论