- 浏览: 81907 次
最新评论
-
liang1022:
Groovy 腳本語言在功能上可以取代javax.script ...
JAVA6.0操作脚本语言 -
venus224:
感谢你!
是你让我进入了开发这个行业!
JAVA截屏程序(第四版) -
wendal:
不错嘛, 正好可以用上.
JAVA截屏程序(第四版) -
muqingren:
貌似没有贴完啊
日期选择器 -
keling:
第三、四版附件资源均找不到啦,可否也email一份给我学习下呀 ...
JAVA截屏程序(第四版)
今天看到一本书上写的,有关定义实体BEAN的一些细节,直到今天才知道其中的差别
代码如下:
java 代码1
- /*
- * Test.java
- *
- * Created on 2006年12月15日, 上午12:06
- *
- * To change this template, choose Tools | Template Manager
- * and open the template in the editor.
- */
- package com.hadeslee.entity;
- import java.io.Serializable;
- import javax.persistence.Entity;
- import javax.persistence.GeneratedValue;
- import javax.persistence.GenerationType;
- import javax.persistence.Id;
- /**
- * Entity class Test
- *
- * @author lbf
- */
- @Entity
- public class Test implements Serializable {
- private Long id;
- private String name,sex,age;
- private int idCard;
- /** Creates a new instance of Test */
- public Test() {
- }
- /**
- * Gets the id of this Test.
- * @return the id
- */
- @Id
- @GeneratedValue(strategy = GenerationType.AUTO)
- public Long getId() {
- return this.id;
- }
- /**
- * Sets the id of this Test to the specified value.
- * @param id the new id
- */
- public void setId(Long id) {
- this.id = id;
- }
- public void setNameID(int ids){
- this.idCard=ids;
- }
- public int getNameID(){
- return idCard;
- }
- /**
- * Returns a hash code value for the object. This implementation computes
- * a hash code value based on the id fields in this object.
- * @return a hash code value for this object.
- */
- @Override
- public int hashCode() {
- int hash = 0;
- hash += (this.id != null ? this.id.hashCode() : 0);
- return hash;
- }
- /**
- * Determines whether another object is equal to this Test. The result is
- * <code>true</code> if and only if the argument is not null and is a Test object that
- * has the same id field values as this object.
- * @param object the reference object with which to compare
- * @return <code>true</code> if this object is the same as the argument;
- * <code>false</code> otherwise.
- */
- @Override
- public boolean equals(Object object) {
- // TODO: Warning - this method won't work in the case the id fields are not set
- if (!(object instanceof Test)) {
- return false;
- }
- Test other = (Test)object;
- if (this.id != other.id && (this.id == null || !this.id.equals(other.id))) return false;
- return true;
- }
- /**
- * Returns a string representation of the object. This implementation constructs
- * that representation based on the id fields.
- * @return a string representation of the object.
- */
- @Override
- public String toString() {
- return "com.hadeslee.entity.Test[id=" + id + "]";
- }
- public String getName() {
- return name;
- }
- public void setName(String name) {
- this.name = name;
- }
- public String getSex() {
- return sex;
- }
- public void setSex(String sex) {
- this.sex = sex;
- }
- public String getAge() {
- return age;
- }
- public void setAge(String age) {
- this.age = age;
- }
- }
java 代码2
- /*
- * Test.java
- *
- * Created on 2006年12月15日, 上午12:06
- *
- * To change this template, choose Tools | Template Manager
- * and open the template in the editor.
- */
- package com.hadeslee.entity;
- import java.io.Serializable;
- import javax.persistence.Entity;
- import javax.persistence.GeneratedValue;
- import javax.persistence.GenerationType;
- import javax.persistence.Id;
- /**
- * Entity class Test
- *
- * @author lbf
- */
- @Entity
- public class Test implements Serializable {
- @Id
- @GeneratedValue(strategy = GenerationType.AUTO)
- private Long id;
- private String name,sex,age;
- private int idCard;
- /** Creates a new instance of Test */
- public Test() {
- }
- /**
- * Gets the id of this Test.
- * @return the id
- */
- public Long getId() {
- return this.id;
- }
- /**
- * Sets the id of this Test to the specified value.
- * @param id the new id
- */
- public void setId(Long id) {
- this.id = id;
- }
- public void setNameID(int ids){
- this.idCard=ids;
- }
- public int getNameID(){
- return idCard;
- }
- /**
- * Returns a hash code value for the object. This implementation computes
- * a hash code value based on the id fields in this object.
- * @return a hash code value for this object.
- */
- @Override
- public int hashCode() {
- int hash = 0;
- hash += (this.id != null ? this.id.hashCode() : 0);
- return hash;
- }
- /**
- * Determines whether another object is equal to this Test. The result is
- * <code>true</code> if and only if the argument is not null and is a Test object that
- * has the same id field values as this object.
- * @param object the reference object with which to compare
- * @return <code>true</code> if this object is the same as the argument;
- * <code>false</code> otherwise.
- */
- @Override
- public boolean equals(Object object) {
- // TODO: Warning - this method won't work in the case the id fields are not set
- if (!(object instanceof Test)) {
- return false;
- }
- Test other = (Test)object;
- if (this.id != other.id && (this.id == null || !this.id.equals(other.id))) return false;
- return true;
- }
- /**
- * Returns a string representation of the object. This implementation constructs
- * that representation based on the id fields.
- * @return a string representation of the object.
- */
- @Override
- public String toString() {
- return "com.hadeslee.entity.Test[id=" + id + "]";
- }
- public String getName() {
- return name;
- }
- public void setName(String name) {
- this.name = name;
- }
- public String getSex() {
- return sex;
- }
- public void setSex(String sex) {
- this.sex = sex;
- }
- public String getAge() {
- return age;
- }
- public void setAge(String age) {
- this.age = age;
- }
- }
代码1和代码2唯一的差别就是@Id的注释地方不同了
同样是注释主键,当在直接用在变量上注释时,如果其它的成员变量没有指定名字,则数据库生成的表的各列名字将以定义的成员变量的变量名为准
当用在getter方法注释时,则数据库生成的表的各列名字将取getXXXX的XXXX名字,将不再取定义的成员变量名
像上面的例子中,代码1会有IdCard这一列,则代码2取而代之的将是NameID这一列.这看上去是一个小小的差别,但是了解了终究是好事.呵呵.终于懂清楚在get上注释和直接在成员变量上注释的差别了,一般来说是不会有什么差别的,一般标准 的JAVABEAN都是成员变量名和getter,setter签名一样的.
好了,睡觉去了
发表评论
-
EJB初学日记(3)
2007-09-08 10:13 1296今天主要是看了一下拦 ... -
七种映射关系
2006-12-17 23:25 2027直到现在我对映射关系都不是非常了解,希望以后有个更深的了解,今 ... -
关于session bean的一些细节
2006-12-14 16:30 2506session BEAN一般用于操作 ... -
EJB中实现的AOP
2006-12-14 11:27 2866现在AOP是越来越流行了,面向切面的编程,呵呵,似乎比面向对象 ... -
实体BEAN的关联
2006-12-13 18:33 1455今天自己写了一个例子,有关实体BEAN的关联问题,我写的这个例 ... -
如何在应用程序中访问绑定的EJB?
2006-12-12 17:46 2413今天又有问题了,所有的例子都是在WEB页面里面调用EJB的,这 ... -
昨天的问题终于解决了
2006-12-11 17:08 1664唉,真是太高兴了.昨天 ... -
NBNB我爱你
2006-12-11 15:04 1365这几天一直都发现NB莫名奇妙的出一些错误,经常空指针异常,这不 ... -
确实不爽
2006-12-10 19:08 4730今天真是郁闷,每次都试不好,唉,话不多说,把代码帖出来吧 ja ... -
J2EE初学3
2006-12-10 16:24 1445stateless Session Bean与stateful ... -
EJB3.0规范解读(转)
2006-12-08 16:18 1409引言 在本文 ... -
J2EE初学2
2006-12-08 11:56 1194今天看到了实体BEAN,(Enti ... -
J2EE初学
2006-12-07 22:31 1536今天终于还是下定决心看看EJB,看着SPRING看了两天,觉得 ...
相关推荐
一方面出于对mootools的兴趣(虽然没有jQuery那么hot), 另一方面,也是想为mootools的推广添一点小小的力量,虽然这微不足道. 加上前面发布过的2个mootools组件, 写下来总的感觉是: 在效果实现方面, 确实用jQuery编写要...
老乔布斯说过,所谓的微创新,并不是让你把过去的东西都推翻掉,而是在过去的基础上去不断的调整和变化,甚至可能只是一点小小的功能,但是最后给客户带来的体验是非常棒的,这就是微创新。对一个成功的产品来说,再...
如果一个问题牵扯的面比较广,就干脆到网上搜索一些相关的专题,比如“java 乱码 mysql” “oracle 创建用户”等等,如果有必要,不要犯懒,勤动手写一些小小的测试程序,来弄明白知识点的细节。这也是涨知识的重要...
这就需要在商品product中加入Observer这样角色,以便product细节发生变化时,Observer能自动观察到这种变化,并能进行及时的update动作. <br>2、适配器模式 <br> 小小最爱喝饮料,可妈妈不让,每天都用保温杯给她...
小小的GPS是如何只在几秒钟内就从无数条可能路径中找出到达目的地的最快捷路径的呢?在网上购物时,又如何防止他人窃取你的信用卡账号呢?解决这些问题,以及大量其他问题的答案均是算法。我写本书的目的就是为你...
书中讲解了大量在开发操作系统中需注意的细节问题,这些细节不仅能使读者更深刻地认识操作系统的核心原理,而且使整个开发过程少走弯路。本书分上下两篇,共11章。其中每一章都以前一章的工作成果为基础,实现一项新...
书中讲解了大量在开发操作系统中需注意的细节问题,这些细节不仅能使读者更深刻地认识操作系统的核心原理,而且使整个开发过程少走弯路。本书分上下两篇,共11章。其中每一章都以前一章的工作成果为基础,实现一项新...
还有更多小小的细节.... 移除自动安装功能 2009.04.21 - 2.0 增强定时器功能 定时关机功能 周期功能 自定义名称 过期在下次启动时会提示了 添加任务栏支持显示CPU和网络 定时器和系统设置分开 ...
本书这一版本充分体现了这一点。第4版的改动为了体现现代C++编程风格,我们重新组织并重写了本书。书中不再强调低层编程技术,而把中心转向标准库的使用。书中很早就开始介绍标准库,示例也已经重新改写,充分利用了...
本书这一版本充分体现了这一点。第4版的改动为了体现现代C++编程风格,我们重新组织并重写了本书。书中不再强调低层编程技术,而把中心转向标准库的使用。书中很早就开始介绍标准库,示例也已经重新改写,充分利用了...
多一点细节 Git-meta既描述了体系结构,又提供了一组工具来促进单仓库和相关工作流程的实施。 除了能够安装此存储库中提供的工具之外,git-meta仅需要Git。 Git-meta不与任何特定的Git托管解决方案绑定,并
你如果喜欢可以在这道炖菜里加上各种时蔬,比如胡萝卜,白萝卜,蘑菇等等,有时候一点小小的创意,会给你的菜式带来意想不到的效果。这道爱尔兰炖牛肉的小秘密就是啤酒的使用,传统的做法是用爱尔兰的黑啤来炖煮牛肉...