what happens in more sophisticated environments where you do not necessarily know ahead of time which bean class

you are going to be using, or which property you want to retrieve or modify?

The APIs in the BeanUtils package are intended to simplify getting and setting bean properties dynamically, where the

objects you are accessing -- and the names of the properties you care about -- are determined at runtime in your

application, rather than as you are writing and compiling your application's classes.

1.getSimpleProperty()读取属性

 Person person=new Person();
person.setName=("heis");
String name=(String)PropertyUtils.getSimpleProperty(person,"name");

2.getNestedProperty()检索嵌套的bean属性

 Book book=new Book();
book.setAuthor(person);
String authorName=(String)PropertyUtils.getNestedProperty(book,"author.name");

3. getIndexedProperty()访问数组或List型内Object的属性

 Chapter chapter1=new Chapter();
Chapter chapter2=new Chapter();
book.getChapters().add(chapter1);
book.getChapters().add(chapter2);
Chapter chapter=(Chapter)PropertyUtils.getIndexedProperty(book,"chapter[0]");

4.getMappedProperty()访问Map型bean属性的值

 Person person=new Person();
person.setName=("heis");
Map favorites=new HashMap();
favorites.put("food","rice");
person.setFavorite(favorites);
String favorFood=(String)PropertyUtils.getMappedProperty(person,"favorites(food)");

5.getProperty()和setProperty()可以访问任何bean属性,通过表达式可以完成上面方法的功能

 Book book
|--List authors
|--[0]->Person person
|--Map favorites
|--Entry(key->"food",value->"")
PropertyUtils.setProperty(book,"authors[0].favorites(food)","rice");
String favorFood=(String)PropertyUtils.getProperty(book,"authors[0].favorites(food)");

BeanUtils 学习教程的更多相关文章

  1. Deep Learning 19_深度学习UFLDL教程:Convolutional Neural Network_Exercise(斯坦福大学深度学习教程)

    理论知识:Optimization: Stochastic Gradient Descent和Convolutional Neural Network CNN卷积神经网络推导和实现.Deep lear ...

  2. WebPack 简明学习教程

    WebPack 简明学习教程 字数1291 阅读22812 评论11 喜欢35 WebPack是什么 一个打包工具 一个模块加载工具 各种资源都可以当成模块来处理 网站 http://webpack. ...

  3. MyBatis入门学习教程-使用MyBatis对表执行CRUD操作

    上一篇MyBatis学习总结(一)--MyBatis快速入门中我们讲了如何使用Mybatis查询users表中的数据,算是对MyBatis有一个初步的入门了,今天讲解一下如何使用MyBatis对use ...

  4. 深入浅出的javascript的正则表达式学习教程

    深入浅出的javascript的正则表达式学习教程 阅读目录 了解正则表达式的方法 了解正则中的普通字符 了解正则中的方括号[]的含义 理解javascript中的元字符 RegExp特殊字符中的需要 ...

  5. 子类重载父类的方法“parent::方法名”转于 恩聪PHP学习教程

    在PHP中不能定义重名的函数,也包括不能再同一个类中定义重名的方法,所以也就没有方法重载.单在子类中可以定义和父类重名的方法,因为父类的方法已经在子类中存在,这样在子类中就可以把从父类中继承过来的方法 ...

  6. LaTeX学习教程

    本来我对LaTeX不是看好的,毕竟都是命令格式的.觉得有word就足够啦word可视化操作方便快捷. 但是由于要写论文等,在导师要求下潜心学习一下,不知不觉间被LaTeX的强大功能所吸引.现在很多出版 ...

  7. Deep Learning 13_深度学习UFLDL教程:Independent Component Analysis_Exercise(斯坦福大学深度学习教程)

    前言 理论知识:UFLDL教程.Deep learning:三十三(ICA模型).Deep learning:三十九(ICA模型练习) 实验环境:win7, matlab2015b,16G内存,2T机 ...

  8. Deep Learning 12_深度学习UFLDL教程:Sparse Coding_exercise(斯坦福大学深度学习教程)

    前言 理论知识:UFLDL教程.Deep learning:二十六(Sparse coding简单理解).Deep learning:二十七(Sparse coding中关于矩阵的范数求导).Deep ...

  9. Deep Learning 11_深度学习UFLDL教程:数据预处理(斯坦福大学深度学习教程)

    理论知识:UFLDL数据预处理和http://www.cnblogs.com/tornadomeet/archive/2013/04/20/3033149.html 数据预处理是深度学习中非常重要的一 ...

随机推荐

  1. Spring的国际化资源messageSource

    Spring中可以使用两个类加载资源文件:ReloadableResourceBundleMessageSource和ResourceBundleMessageSource. 可配置如下message ...

  2. A C[HDU1570]

    A C Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...

  3. Zepto源码注释

    /* Zepto v1.0-1-ga3cab6c - polyfill zepto detect event ajax form fx - zeptojs.com/license */ ;(funct ...

  4. topcoder 594 DIV2 foxandclassroom

    暴力枚举 1 #include <iostream> #include <vector> #include <string> using namespace std ...

  5. SecureCrt脚本(一)顶级对象之Crt

    Crt自动化 测试 SecureCrt脚本 JS脚本   1.引言 2.关于脚本表头 3.顶级对象'crt'的子属性和方法 3.1.属性 3.1.1.Dialog 3.1.2.Screen 3.1.3 ...

  6. JQuery获取和设置Select选项常用方法总结 (转)

    1.获取select 选中的 text: $("#cusChildTypeId").find("option:selected").text(); $(&quo ...

  7. sqlmap遇到url重写的示例

    url_rewrite 这个问题 国内外的坛子里都有人问. D:\cygwin\pentest\database\sqlmap\doc \faq.pdf 下面是官方给的解答. 1.15 How to ...

  8. Json 数据

    来自:极课学院 简介: json与xml json语法 json对象 json对象数组 用到的包 读取json数据例子 创建json数据

  9. vb.net-三种将datagridview数据导出为excel文件的函数

    第一种方法较慢,但是数据格式都比较好,需要引用excel的 Microsoft.Office.Interop.Excel.dll  office.dll #Region "导出excel函数 ...

  10. Hadoop及子项目备注

    Hadoop CommonHadoop体系最底层的一个模块,为Hadoop各子项目提供各种工具,如:配置文件和日志操作等. AvroAvro是doug cutting主持的RPC项目,有点类似Goog ...