ITeye博客

Java

共 36 篇文章

lombok的canEqual/equals

public boolean equals(Object o) { if (o == this) return true; if (!(o instanceof PayType)) return false; PayType other = (PayType)o; return other.canEqual(this); } public boolean canEqual(Object other) { return other instanceof PayType; } 要是一个类没有属性,那么equals方法就悲剧了。 恰巧,我在一个子类总使用了@Data,覆盖了父类的equlas,然后…

2011-11-22 17:22 · Java

getReference

Get an instance, whose state may be lazily fetched. If the requested instance does not exist in the database, throws EntityNotFoundException when the instance state is first accessed. (The persistence provider runtime is permitted to throw EntityNotFoundException when getReference(java.lang.Class, …

2011-08-16 10:55 · Java

怎么写,程序才能死锁?

若不了解线程,事务,死锁相关的基础知识,请先去了解一下,一点点儿基础知识就okay啦. 第一部分,线程死锁 利用synchronized模拟一下线程死锁 public class Synchron { public void begin() { Thread t1 = new Thread(new Thread1()); Thread t2 = new Thread(new Thread2()); t1.start(); t2.start(); } public static void main(String[] args) { new Synchron().begin(); } publi…

2011-04-05 17:03 · Java

附注 OF 《怎么写,程序才能死锁?》

这只是一篇 附注 ,请看博客文章 怎么写,程序才能死锁? http://keating.iteye.com/blog/983365 参考1,线程死锁 ||Thread1|Thread2| |目的|获取i|获取j| |步骤|获取i|获取j| ||等待j被释放,获取j|等待i被释放,获取i ||释放i|释放j| public class NewClass { boolean i = false; boolean j = false; public void begin() { Thread t1 = new Thread(new Thread1()); Thread t2 = new Threa…

2011-04-05 17:03 · Java

以is作为名称开头的属性,它的Getter方法名应该是什么样的?

--> private String isAbc; when use eclipse, we can generate getter for the attribute isAbc: public String getIsAbc() { return isAbc; } --> private @Getter String isAbc; when use lombok, I get the getter public String isAbc() { return isAbc; } The two getters have different names. I think eclipse is…

2011-03-21 22:47 · Java

Eclipse新建类中自动添加author.

缘起,我改不了win 7滴user name了,所以只能曲线救国. window -> preference -> java -> code typle -> code template -> Comments -> Types /** * @author ${user} * * ${tags} */ 发现这样可以直接替换掉 ${user} 把author写死. 然后又发现, window -> preference -> java -> code typle -> code template -> Code -> New Java files -> Edit ${filecomment} …

2010-10-17 11:52 · Java

<effective java>讲for的笔记

先是说for比while更安全,因为for是把一推东西都写在括号中的嘛. 而while需要现在外部定义一个对象, 所以,while中可能出现如此代码, Iterator<Element> i = c.iterator(); while(i.hasNext()){ doSomething(i.next()); } //... Iterator<Element> i2 = c2.iterator(); while(i.hasNext()){//这里有bug doSomething(i2.next()); } for循环就不可能出现. 然后,就是一个比较有意思的,可能你知道,算俺少见多怪吧... …

2010-09-25 10:14 · Java

字符串加法与StringBuilder.append()

public class Main { /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here int times = 1000;// 次数 long beginBuilder = System.currentTimeMillis(); StringBuilder builder = new StringBuilder(); for (int i = 0; i < times; i++) { buil…

2010-09-24 13:21 · Java

JPA 2 Inheritance

父类Super, @Entity public class Super { @GeneratedValue(strategy = GenerationType.AUTO) @Id private int id; private String name; //getters and setters... } 然后,两个子类, @Entity public class M extends Super { private String mName; //getters and setters... } @Entity public class N extends Super { private S…

2010-09-23 21:41 · Java

JDBC,JPA存储枚举..

实体类, @Entity public class H { @GeneratedValue(strategy = GenerationType.AUTO) @Id private int id; private String name; private Operation op; public H(){} public H(String name, Operation op){ this.name = name; this.op = op; } //getters and setters... } 上面类中op是个枚举对象, public enum Operation { PLUS("+")…

2010-09-18 22:05 · Java

Embeddable Class 之内,可以使用 @OneToMany

@Entity public class H { @GeneratedValue(strategy = GenerationType.AUTO) @Id int id; String name; @Embedded I i; } @Embeddable public class I { String iName; @OneToMany(cascade = { PERSIST, REMOVE }) List<J> j = new ArrayList<J>(); } @Entity public class J { @GeneratedValue(strategy = GenerationTyp…

2010-09-18 19:54 · Java

JPA2.0使用Map (2) 双向一对多,令人湿望的Hibernate

@Entity public class E { @GeneratedValue(strategy = GenerationType.AUTO) @Id int id; String name; @OneToMany(mappedBy = "e") @MapKeyColumn(name = "kkk") Map<String,F> f = new HashMap<String,F>(); } @Entity public class F { @GeneratedValue(strategy = GenerationType.AUTO) @Id int id; String name; @Ma…

2010-09-14 08:28 · Java

JPA2.0使用Map (1) 单向一对多,令人湿望的EclipseLink

@Entity public class E implements Serializable { @GeneratedValue(strategy = GenerationType.AUTO) @Id int id; String name; @OneToMany(cascade={PERSIST,REMOVE}) Map<String, F> f = new HashMap<String, F>(); } @Entity public class F implements Serializable { @GeneratedValue(strategy = GenerationType.AU…

2010-09-14 08:28 · Java

更改 .java 文件的编码格式

杯具呀..eclipse的默认编码是GBK,俺作为新鸟,直接用了GBK,于是乎被责成把所有class换成utf-8编码... :cry: 于是乎,自然而然想到了俺的FileOperator Class,它有两个读写文件的方法,一个读,一个写.当然还是很智能滴可以指定编码滴...恩,好说,可以把项目底下所有的java class以gbk编码读出来,then用utf-8血淋淋地写回去...sai... First,我先写遍历项目文件夹的方法吧...于是乎,它诞生鸟—— import java.io.File; import java.util.ArrayList; import java.uti…

2010-09-05 09:18 · Java

Netbeans generate config files for JTA Transaction automatically

If you are using Netbeans, you are lucky. When you create the persistence.xml, netbeans will help you build the config-xml of JTA automatically. I use Netbeans 6.9, EJB 3.1, JPA 2.0, JSF 2.0. But, if you are using eclipse, you should modify the content of persistence.xml, maybe it should like this:…

2010-09-04 09:40 · Java

A-->B 有两个..How JPA do ?

Class B is easy: import java.io.Serializable; import javax.persistence.*; /** * Entity implementation class for Entity: B * */ @Entity public class B implements Serializable { public B() { super(); } @GeneratedValue(strategy = GenerationType.AUTO) @Id private int id; private String name; public int…

2010-09-02 21:06 · Java

A-->List<B> 有两个..How JPA do ?

Compare to the previous one(I mean 'A-->B 有两个..How JPA do ?'), I only add a constructor to Class B: import java.io.Serializable; import javax.persistence.*; /** * Entity implementation class for Entity: B * */ @Entity public class B implements Serializable { public B() { super(); } public B(String …

2010-09-02 21:06 · Java

Java读写XML工具类

/* * To change this template, choose Tools | Templates * and open the template in the editor. * 读xml文件 */ package util.xml; import java.io.*; import java.util.Vector; import java.util.logging.Level; import java.util.logging.Logger; import org.w3c.dom.*; import javax.xml.parsers.*; import org.xml.sa…

2010-02-07 14:25 · Java

使用POI, 我的Excel操作类

/* * To change this template, choose Tools | Templates * and open the template in the editor. * 获得、设置单元格的内容 */ package util.excel; import java.text.DecimalFormat; import org.apache.poi.hssf.usermodel.HSSFCell; import org.apache.poi.ss.usermodel.Cell; /** * * @author Administrator */ public class Ce…

2010-01-08 10:25 · Java

FileOperater

import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; /** * 文件操作类 * * @author keating */ public class FileOperater { /** * 文件复制方法 * @throws…

2010-01-08 10:22 · Java