自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

講述Hibernate Utilities

開發(fā) 后端
這里介紹Hibernate Utilities類,我們需要三樣東西:定義這些類的 TLD 文件、Hibernate Utilities 中的函數(shù),以及標簽文件本身,后者要使用這些函數(shù)。

Hibernate還是比較常用的,于是我研究了一下Hibernate Utilities,在這里拿出來和大家分享一下,希望對大家有用。

Hibernate Utilities類

以下代碼其中包含了標簽文件使用的所有函數(shù),最適合使用 Java 代碼編寫的代碼都被放到了幾個 TLD 可以映射的函數(shù)中,這樣標簽文件就可以使用它們了;這些函數(shù)都是在Hibernate Utilities 類中進行編碼的。因此,我們需要三樣東西:定義這些類的 TLD 文件、Hibernate Utilities 中的函數(shù),以及標簽文件本身,后者要使用這些函數(shù)。(第四樣應該是使用這個標簽文件的 JSP 頁面。)

以下,給出了在 TLD 中引用的函數(shù)和另外一個表示給定屬性是否是 Date 的方法。在這個類中要涉及到比較多的代碼,但是本文限于篇幅,不會給出所有的代碼;不過需要注意 findGetterMethod() 除了將表達式語言(Expression Language,EL)方法表示(customer.contact)轉(zhuǎn)換成 Java 表示(customer.getContact())之外,還執(zhí)行了基本的映像操作。

Hibernate Utilities節(jié)選

  1. public static Boolean required(Object object, String propertyPath) {  
  2. Method getMethod = findGetterMethod(object, propertyPath);  
  3. if (getMethod == null) {  
  4. return null;  
  5. } else {  
  6. return getMethod.isAnnotationPresent(NotNull.class);  
  7. }  
  8. }  
  9.  
  10. public static Boolean isDate(Object object, String propertyPath) {  
  11. return java.util.Date.class.equals(getReturnType(object, propertyPath));  
  12. }  
  13.  
  14. public static Class getReturnType(Object object, String propertyPath) {  
  15. Method getMethod = findGetterMethod(object, propertyPath);  
  16. if (getMethod == null) {  
  17. return null;  
  18. } else {  
  19. return getMethod.getReturnType();  
  20. }  

此處可以清楚地看到在運行時使用 Validation annotations 是多么容易??梢院唵蔚匾脤ο蟮?getter 方法,并檢查這個方法是否有相關(guān)的給定的注釋 。

【編輯推薦】

  1. 剖析Hibernate Extensions
  2. 介紹Hibernate Iterator方法
  3. Hibernate Session緩存經(jīng)驗總結(jié)
  4. 簡單介紹Hibernate配置Proxool
  5. 淺談Hibernate outer-join參數(shù)
責任編輯:佚名 來源: 51cto技術(shù)博客
相關(guān)推薦

2009-09-25 10:00:47

Hibernate映射

2009-09-24 10:40:19

Hibernate核心

2009-09-24 10:06:42

Hibernate實例

2009-09-28 10:14:08

Hibernate基礎(chǔ)

2009-09-25 13:51:13

Hibernate S

2009-09-25 12:59:52

Hibernate映射

2009-09-25 13:39:40

Hibernate屬性

2009-09-25 15:03:21

Hibernate綁定

2009-09-27 13:25:22

2009-06-17 09:17:41

Hibernate3

2009-11-17 16:53:24

PHP遞歸算法

2010-02-02 09:08:39

Python 特性

2010-05-28 18:37:11

MySQL管理

2009-10-10 09:57:58

使用RHEL合法

2010-03-10 17:37:48

Linux磁盤配額

2009-10-26 10:24:35

linux脫機打印命令

2012-02-08 14:24:35

HibernateJava

2009-12-24 17:37:26

ADO分頁

2009-12-24 13:46:23

Linux驅(qū)動

2009-12-30 17:38:53

點贊
收藏

51CTO技術(shù)棧公眾號