为什么要使用hibernate注解? [英] Why do we use hibernate annotation?

查看:30
本文介绍了为什么要使用hibernate注解?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么重要?根据 XML 映射有什么优势?你能解释一下这些吗?谢谢.

Why is it important? what are advantage according to XML mapping? Can you explan these? thank you.

推荐答案

它不像强制"那样重要.这是一种不同的可能性,有优势也有弱点.

It is not something important as in "mandatory". It's a different possibility, with strength and weaknesses.

优点:

  • 编译时检查:如今在 IDE 中使用 Java(而不是 Xml)编写非常方便用户.没有更多的错别字在启动您的应用程序时发现(增量编译),不需要记住太多(完成)...
  • 使用代码(类级别)本地化:不必打开两个文件(java 和 xml)来获取完整故事,只需一个带注释的 java 文件,您只需打开一个文件.从长远来看,这会减少重复,速度会更快.
  • 用代码(方法或字段级别)本地化:因为注释在方法(或字段)上,所以无需指定它所属的方法.没有给出多余的信息,它更短,而且总是连贯的(例如,即使在代码重构之后).维护速度要快得多.
  • 工具(javadoc,其他使用反射的工具)可以使用注释来满足其他一些要求.
  • 注释比 xml 更新,团队使用他们当时收到的输入来提供更好的默认值.Xml 有一些,但出于兼容性原因不能改变太多.通常,使用注释技术时,您根本不编写注释,它就可以运行.想象一下节省的时间,尤其是在开发过程中.
  • Compile-time checking : writing in Java (instead of Xml) is very user-friendly in the IDE nowadays. No more typos discovered when starting your application (incremental compilation), not that much to remember (completion)...
  • Localized with the code (class level) : instead of having to open two files (java and xml) to get the full story, with one annotated java file, you open only one file. This is less repetitive, faster in the long run.
  • Localized with the code (method or field level) : because the annotation go on a method (or field), there is no need to specify the method it belongs to. That redondant information is not given, which is shorter, and always coherent (even after a code refactoring for example). Maintenance is so much faster.
  • Tools (javadoc, other tools using reflection) can use the annotations for some other requirements.
  • Annotations are newer than the xml, the team used the input they had received at the time to provide better default values. Xml has some, but can't change much for compatibility reasons. Often, with the annotations technology, you write no annotation at all, and it works. Imagine the time-saving, especially during development.

这篇关于为什么要使用hibernate注解?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆