java bean 和 java 类之间的区别?

发布于 2024-12-22 17:03:59 字数 163 浏览 3 评论 0原文

我是 JSP 和服务器端编程的新手。到目前为止,我正在使用 Servlet 和 java 类。我在 java 类的帮助下隔离我的应用程序(根据 MVC 模型)。我想知道java bean 和java 类之间的区别。在这种情况下我可以使用 java bean 而不是 java 类。有任何有用的解释或有用的链接吗?

I am new to the JSP and server side programming. Till now I am working with Servlets and java classes. I am segregating my application (as per MVC model) with the help of java classes. I would like to know difference between java beans and java classes. And in which scenario I can use a java bean instead of a java class. Any helpful explanation or helpful links?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

£冰雨忧蓝° 2024-12-29 17:03:59

Java bean 只是一个符合某些约定的类:

  • 可以通过 getter 访问的属性(如果这些属性不是只读,则可以通过 setter 访问)
  • 无参数 公共构造函数
  • 可序列化

JSP EL 和标记是围绕这些约定设计的。他们中的大多数人不需要遵守所有这些惯例。 getter 可用的属性是这些约定中最重要的。例如,表达式

${foo.bar.name}

显示 foo bean 的 bar 的名称。 foo 是一个必须位于页面、请求、会话或应用程序上下文中的 bean。此表达式将调用此 bean 上的 getBar(),然后调用 getBar() 返回的对象上的 getName()

A Java bean is just a class which conforms to some conventions:

  • properties that can be accessed by getters (and setters if those properties are not read-only)
  • no-arg public constructor
  • serializable

The JSP EL and tags are designed around those conventions. Most of them don't need all these conventions to be respected. properties available by getters is the most important of these conventions. For example, the expression

${foo.bar.name}

displays the name of the bar of the foo bean. foo is a bean that must be in the page, request, session or application context. And this expression will call getBar() on this bean, and then getName() on the object returned by getBar().

ぽ尐不点ル 2024-12-29 17:03:59

JavaBeans 规范将 JavaBeans 组件类型定义为“可重用软件组件”。组件是一个简单的 Java Bean 类,Java 遵守有关方法命名、构造和行为的某些约定。遵守这些约定使得开发工具的使用、重用、替换和连接 Java Bean 成为可能。 bean 必须是“Serialized”才能保存和恢复此类的实例。

The JavaBeans specification defines the type JavaBeans components as "reusable software components". A component is a simple Java Bean Class Java respects certain conventions about method naming, construction and behavior. Adherence to these conventions makes it possible to use, reuse, replace and connect Java Beans for development tools. The beans must be "Serializable"In order to save and restore instances of this class.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文