且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

java bean和java类之间的区别?

更新时间:2023-10-06 09:16:46

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