汕头网站制作哪家好,软件开发公司税收优惠政策,企业建网站的 程序,网络营销机构官方网站什么是POJO#xff0c;JavaBean#xff1f;总结#xff1a;POJO#xff1a;一个简单的Java类#xff0c;这个类没有实现/继承任何特殊的java接口或者类#xff0c;不遵循任何主要java模型#xff0c;约定或者框架的java对象。在理想情况下#xff0c;POJO不应该有注解。…什么是POJOJavaBean总结POJO一个简单的Java类这个类没有实现/继承任何特殊的java接口或者类不遵循任何主要java模型约定或者框架的java对象。在理想情况下POJO不应该有注解。JavaBeanJavaBean是可序列化的实现了serializable接口具有一个无参构造器有按照命名规范的set和gettis(可以用于访问布尔类型的属性)方法pojoPOJO的创始人(martinfowler)博客The term was coined while Rebecca Parsons, Josh MacKenzie and I were preparing for a talk at a conference in September 2000. In the talk we were pointing out the many benefits of encoding business logic into regular java objects rather than using Entity Beans. We wondered why people were so against using regular objects in their systems and concluded that it was because simple objects lacked a fancy name. So we gave them one, and its caught on very nicely....在谈话中我们指出编写业务逻辑的时候使用常规的java对象要比实体bean要好的多。我们怀疑为什么一些人极力反对在他们的代码中使用常规对象还辩解称因为这些常规对象没有一个花哨的名字所以我们给他们起了一个非常好听的名字。(Plain Old Java Object)维基百科原文————(以下代码和示例均来源于此)The term POJO initially denoted a Java object which does not follow any of the major Java object models, conventions, or frameworks; nowadays POJO may be used as an acronym for Plain Old JavaScript Object as well, in which case the term denotes a JavaScript object of similar pedigree.[2]术语POJO起初表示为不遵任何主要的java模型约定或者框架的java对象现在pojo也可以用作Plain Old JavaScript Object的缩写这样的话和javascript对象有着相似的渊源。理想状态下pojo应该是一个不受Java语言规范限制的java对象。换句话说pojo不应该1.继承预先设定的类如public class Foo extends javax.servlet.http.HttpServlet {// ...}2.实现预先设定的接口如public class Bar implements javax.ejb.EntityBean {// ...}3.包含预先指定的注解如javax.persistence.Entitypublic class Baz {// ...}However, due to technical difficulties and other reasons, many software products or frameworks described as POJO-compliant actually still require the use of prespecified annotations for features such as persistence to work properly. The idea is that if the object (actually class) was a POJO before any annotations were added, and would return to POJO status if the annotations are removed then it can still be considered a POJO. Then the basic object remains a POJO in that it has no special characteristics (such as an implemented interface) that makes it a Specialized Java Object (SJO or (sic) SoJO).然而由于技术和其他原因很多被称之为POJO标准的软件产品或框架仍然需要使用特定的注解来保证持久化等功能。这个想法是如果对象(类)在任何注解添加之前是一个pojo的话并且注解移除之后仍然是pojo。所以最基础的pojo解释是没有特别的特征(尤其是实现接口之类的)使其称之为“专用java对象”JavaBeanA JavaBean is a POJO that is serializable, has a no-argument constructor, and allows access to properties using getter and setter methods that follow a simple naming convention. Because of this convention, simple declarative references can be made to the properties of arbitrary JavaBeans. Code using such a declarative reference does not have to know anything about the type of the bean, and the bean can be used with many frameworks without these frameworks having to know the exact type of the bean. The JavaBeans specification, if fully implemented, slightly breaks the POJO model as the class must implement the Serializable interface to be a true JavaBean. Many POJO classes still called JavaBeans do not meet this requirement. Since Serializable is a marker (method-less) interface, this is not much of a burden.JavaBean是一个可序列化的POJO具有一个无参构造器并且允许使用遵循简单命名约定的getter和setter方法来访问属性。由于这个惯例可以对任意JavaBean属性进行简单的声明引用。使用这种声明引用的代码不需要知道bean的具体类型。并且这个bean还可以被很多框架使用这些java框架也不需要知道bean的类型。由于java.io.Serializable是一个标记接口(无方法)所以这并不是一个多大的负担。如果JavaBean完全实现的话稍微打破了一些POJO模型。很多被称之为JavaBean的POJO类并不符合这个要求因为JavaBean必须实现Serializable接口才能成为真正的JavaBean。JavaBean的优点The properties, events, and methods of a bean can be exposed to another application.A bean may register to receive events from other objects and can generate events that are sent to those other objects.Auxiliary software can be provided to help configure a bean.The configuration settings of a bean can be saved to persistent storage and restored.bean中的属性事件和方法可以暴露给另一个应用程序一个bean可以注册来自于其他对象的事件也可以产生事件并发送给其他对象辅助代码可以提供javabean的配置一个bean的配置设置可以永远被存储和恢复一些疑问什么是事件有什么作用bean如何注册来自于其他对象的事件配置设置如何被存储和恢复serializable接口是做什么的