java bean和java类之间的区别? [英] difference between java bean and java class?

查看:833
本文介绍了java bean和java类之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是JSP和服务器端编程的新手。直到现在我正在使用Servlets和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?

推荐答案

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

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


  • 可以由getter访问的属性(如果这些属性不是只读的,则为setter)

  • no-arg public constructor

  • serializable

JSP EL和标签是围绕这些约定设计的。他们中的大多数都不需要尊重所有这些惯例。 getter提供的属性是这些约定中最重要的。例如,表达式

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}

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

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().

这篇关于java bean和java类之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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