什么是JavaBeans?
参看维基百科,归纳出以下几条:
JavaBeans是指符合某些标准的类, Bean这个名称用于涵盖这个标准, 其目的在于创建可重用的Java组件。
由于Bean是很“死板”的东西,因此它可以持久存储,并可以借助辅助软件快速实现。
Bean有它专属的一套API。
JavaBean conventions[edit]
In order to function as a JavaBean class, an object class must obey certain conventions about method naming, construction, and behaviour. These conventions make it possible to have tools that can use, reuse, replace, and connect Java Beans.
The required conventions are as follows:
- The class must have a public default constructor (with no arguments). This allows easy instantiation within editing and activation frameworks.
- The class properties must be accessible using get, set, is (can be used for boolean properties instead of get), and other methods (so-called accessor methods and mutator methods) according to a standard naming convention. This allows easy automated inspection and updating of bean state within frameworks, many of which include custom editors for various types of properties. Setters can have one or more than one argument.
- The class should be serializable. (This allows applications and frameworks to reliably save, store, and restore the bean's state in a manner independent of the VM and of the platform.)
实例,1无参构造器 2getter, setter 3实现序列化
package player; public class PersonBean implements java.io.Serializable { /**
* Property <code>name</code> (note capitalization) readable/writable.
*/
private String name = null; private boolean deceased = false; private List list; public List getList() {
return list;
} public void setList(List list) {
this.list= list;
}
/** No-arg constructor (takes no arguments). */
public PersonBean() {
} /**
* Getter for property <code>name</code>
*/
public String getName() {
return name;
} /**
* Setter for property <code>name</code>.
* @param value
*/
public void setName(final String value) {
name = value;
} /**
* Getter for property "deceased"
* Different syntax for a boolean field (is vs. get)
*/
public boolean isDeceased() {
return deceased;
} /**
* Setter for property <code>deceased</code>.
* @param value
*/
public void setDeceased(final boolean value) {
deceased = value;
}
}
在JSP页面中使用PersonBean:
<% // Use of PersonBean in a JSP. %>
<jsp:useBean id="person" class="player.PersonBean" scope="page"/>
<jsp:setProperty name="person" property="*"/> <html>
<body>
Name: <jsp:getProperty name="person" property="name"/><br/>
Deceased? <jsp:getProperty name="person" property="deceased"/><br/>
<br/>
<form name="beanTest" method="POST" action="testPersonBean.jsp">
Enter a name: <input type="text" name="name" size="50"><br/>
Choose an option:
<select name="deceased">
<option value="false">Alive</option>
<option value="true">Dead</option>
</select>
<input type="submit" value="Test the Bean">
</form>
</body>
</html>
什么是JavaBeans?的更多相关文章
- 找规律 ZOJ3498 Javabeans
Javabeans are delicious. Javaman likes to eat javabeans very much. Javaman has n boxes of javabeans. ...
- JavaBeans、EJB和POJO详解
转自:http://developer.51cto.com/art/200906/130814.htm J2EE学习者越来越多,J2EE本身技术不断在发展,涌现出各种概念,本文章试图从一种轻易理解的角 ...
- Java遇见HTML——JSP篇之JavaBeans
一.JavaBean简介及设计原则 设计原则:公有类.无参的公有构造方法.属性私有.有getter and setter方法 实例: 二.Jsp动作元素 JSP动作标签分为五大类: 三.在JSP页面中 ...
- javabeans的运用
javabeans的运用 对javabean的使用我开始严重的郁闷,跟着书上说的做,但是总是不成功.后来别人说我是基础不牢靠.我觉得应该从servlet学起然后再加进入JSP学是非常快的,对于JAVA ...
- [基础规范]JavaBeans规范
本文来自维基百科:http://en.wikipedia.org/wiki/JavaBeans#JavaBean_conventions JavaBeans是Java语言中能够反复使用的软件组件,它们 ...
- Java Web 之javabeans
Java遇见HTML——JSP篇之JavaBeans: http://www.cnblogs.com/Qian123/p/5277425.html
- Java各种对象(PO,BO,VO,DTO,POJO,DAO,Entity,JavaBean,JavaBeans)的区分
PO:持久对象 (persistent object),po(persistent object)就是在Object/Relation Mapping框架中的Entity,po的每个属性基本上都对应数 ...
- Java开发各层对象专用名词含义 PO,VO,DAO,BO,DTO,POJO, BYO,Entity,JavaBean,JavaBeans
Java的几种名词(PO,VO,DAO,BO,POJO)解释 PO:persistant object 持久对象.可以看成是与数据库中的表相映射的java对象.最简单的PO就是对应数据库中某个表中的一 ...
- Java学习之——JavaBeans
1.什么是JavaBeans? JavaBeans是Java语言中可以重复使用的软件组件,它们是一种特殊的Java类,将很多的对象封装到了一个对象(bean)中.特点是 可序列化, 提供无参构造器, ...
- JavaBeans 官方文档学习
提示,重点:JavaBeans的Property和 Events:PropertyEditor极其注册和查找机制. 从目前来看,JavaBeans 更像是源自GUI的需求. 使用NetBeans新建一 ...
随机推荐
- 【转】Monkey测试5-运行中停止monkey
停止monkey自动测试步骤: 1.ps命令 查找uiautomator的进程 打开cmd命令行窗口 输入: adb shell ; ps | grep monkey; 返回来的第一个数字,即是mo ...
- 【HDU 5305】Friends 多校第二场(双向DFS)
依据题意的话最多32条边,直接暴力的话 2 ^ 32肯定超时了.我们能够分两次搜索时间复杂度降低为 2 * 2 ^ 16 唯一须要注意的就是对眼下状态的哈希处理. 我採用的是 十进制表示法 跑的还是 ...
- hive0.13.1安装-mysql server作为hive的metastore
hive0.13.1在hadoop2.4.1伪分布式部署上安装过程 环境:redhat enterprice 6.5 +hadoop2.4.1+hive0.13.1+mysql单节点伪分布式部署 相关 ...
- (转)txt读写 操作封装
[code]csharpcode: using UnityEngine; using System.Collections.Generic; using System.IO; using System ...
- 使用bbed编辑研究oracle数据块结构
bbed是随oracle软件公布的一款数据块查看和编辑工具,作为一款内部工具.bbed的功能很强大,可是假设使用不当可能给数据库造成无法挽回的损失.因此.我们建议在使用bbed改动数据块前备份被改动的 ...
- selenium的元素定位-鼠标事件
鼠标事件 ActionChains 类提供了鼠标操作的常用方法: perform(): 执行所有 ActionChains 中存储的行为: context_click(): 右击: double_cl ...
- 【BZOJ2044】三维导弹拦截 DP+(有上下界的)网络流
[BZOJ2044]三维导弹拦截 Description 一场战争正在A国与B国之间如火如荼的展开. B国凭借其强大的经济实力开发出了无数的远程攻击导弹,B国的领导人希望,通过这些导弹直接毁灭A国的指 ...
- 关于微信小程序的尺寸关系
在微信小程序开发中,大家尽量使用rpx为单位, px实际上就是系统级的rem(把页面按比例分割750份,1rpx=window.innerWidth/750),或者scale伸缩布局的width=75 ...
- php学习笔记8--半边引号引发的问题
前段时间重装了系统,后来说是又要用php,就重新搭建了apache+php+mysql的环境,由于之前搭建过好多次,感觉很easy,很快就搭建完成,然后写了下面的常用的测试环境的代码: <?ph ...
- 子单元通过 prop 接口与父单元进行了良好的解耦
https://cn.vuejs.org/v2/guide/#起步 现在,我们可以使用 v-bind 指令将待办项传到循环输出的每个组件中: <div id="app-7"& ...