温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

如何理解Hibernate Utilities

发布时间:2021-06-16 15:10:30 来源:亿速云 阅读:145 作者:chen 栏目:编程语言

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

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这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是亿速云,小编将为大家推送更多相关知识点的文章,欢迎关注!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI