SSH注解个人整理版.doc
上传人:sy****28 上传时间:2024-09-14 格式:DOC 页数:9 大小:45KB 金币:16 举报 版权申诉
预览加载中,请您耐心等待几秒...

SSH注解个人整理版.doc

SSH注解个人整理版.doc

预览

在线预览结束,喜欢就下载吧,查找使用更方便

16 金币

下载此文档

如果您无法下载资料,请参考说明:

1、部分资料下载需要金币,请确保您的账户上有足够的金币

2、已购买过的文档,再次下载不重复扣费

3、资料包下载后请先用软件解压,在使用对应软件打开

HYPERLINK"http://www.blogjava.net/yxhxj2006/archive/2012/09/20/388114.html"全注解SSH全注解SSH一,hibernateannotationClass注解:1.@Entity:表明当前类是一个持久化类2.@Table(name="team",catalog="NBA"):映射一个表team,所对应的数据库是NBA,可以省略字段属性注解:1.@GenericGenerator(name="generator",strategy="increment")@Id@GeneratedValue(generator="generator")@Column(name="id",unique=true,nullable=false)解释:表明该字段是主键,自增长,不为空而且是唯一的2.@Column(name="description",length=500)解释:映射表中的description字段,长度是5003.@OneToMany(cascade=CascadeType.ALL,fetch=FetchType.LAZY,mappedBy="category")解释:级联操作:cascade=CascadeType.ALL,延迟加载:fetch=FetchType.LAZY,映射:mappedBy="category",一对多方式4.@ManyToOne(fetch=FetchType.LAZY)@JoinColumn(name="category_id")解释:延迟加载:多对一方式,关联信息:外键name="category_id"OneToMany事例代码:数据库:mysqlcategory表:id,name,description(<Pk>id)product表:id,name,price,description,category_id(<pk>id,<fk>category_id)Category.javapackagecom.b510.examples;importjava.util.HashSet;importjava.util.Set;//标准注解importjavax.persistence.CascadeType;importjavax.persistence.Column;importjavax.persistence.Entity;importjavax.persistence.FetchType;importjavax.persistence.GeneratedValue;importjavax.persistence.Id;importjavax.persistence.OneToMany;importjavax.persistence.Table;//增加的注解importorg.hibernate.annotations.GenericGenerator;//当前的类是一个持久化类,是Category这个类。他映射了一个表category。所对应的数据库是users//这句:@Table(name="category",catalog="users")可以省略@Entity@Table(name="category",catalog="users")publicclassCategoryimplementsjava.io.Serializable{privatestaticfinallongserialVersionUID=3240281547213597385L;privateIntegerid;privateStringname;privateStringdescription;privateSet<Product>products=newHashSet<Product>(0);publicCategory(){}publicCategory(Stringname,Stringdescription,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)publicIntegergetId(){