135-1821-9792

如何理解HibernateUtilities

这篇文章主要讲解了“如何理解Hibernate Utilities”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“如何理解Hibernate Utilities”吧!

创新互联专注于企业成都全网营销推广、网站重做改版、南昌县网站定制设计、自适应品牌网站建设、H5开发成都做商城网站、集团公司官网建设、外贸网站建设、高端网站制作、响应式网页设计等建站业务,价格优惠性价比高,为南昌县等各大城市提供网站开发制作服务。

Hibernate还是比较常用的,于是我研究了一下Hibernate Utilities,在这里拿出来和大家分享一下,希望对大家有用。

Hibernate Utilities类

以下代码其中包含了标签文件使用的所有函数,最适合使用 Java 代码编写的代码都被放到了几个 TLD 可以映射的函数中,这样标签文件就可以使用它们了;这些函数都是在Hibernate Utilities 类中进行编码的。因此,我们需要三样东西:定义这些类的 TLD 文件、Hibernate Utilities 中的函数,以及标签文件本身,后者要使用这些函数。(第四样应该是使用这个标签文件的 JSP 页面。)

以下,给出了在 TLD 中引用的函数和另外一个表示给定属性是否是 Date 的方法。在这个类中要涉及到比较多的代码,但是本文限于篇幅,不会给出所有的代码;不过需要注意 findGetterMethod() 除了将表达式语言(Expression Language,EL)方法表示(customer.contact)转换成 Java 表示(customer.getContact())之外,还执行了基本的映像操作。

Hibernate Utilities节选

public static Boolean required(Object object, String propertyPath) {  Method getMethod = findGetterMethod(object, propertyPath);  if (getMethod == null) {  return null;  } else {  return getMethod.isAnnotationPresent(NotNull.class);  }  }   public static Boolean isDate(Object object, String propertyPath) {  return java.util.Date.class.equals(getReturnType(object, propertyPath));  }   public static Class getReturnType(Object object, String propertyPath) {  Method getMethod = findGetterMethod(object, propertyPath);  if (getMethod == null) {  return null;  } else {  return getMethod.getReturnType();  }  }

此处可以清楚地看到在运行时使用 Validation annotations 是多么容易。可以简单地引用对象的 getter 方法,并检查这个方法是否有相关的给定的注释 。

感谢各位的阅读,以上就是“如何理解Hibernate Utilities”的内容了,经过本文的学习后,相信大家对如何理解Hibernate Utilities这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是创新互联,小编将为大家推送更多相关知识点的文章,欢迎关注!


新闻名称:如何理解HibernateUtilities
文章URL:http://kswsj.com/article/jpohdp.html

其他资讯



Copyright © 2009-2022 www.kswsj.com 成都快上网科技有限公司 版权所有 蜀ICP备19037934号