019-使用BeanUtils工具包操作JavaBean
其实自己对JAVABEAN操作真的有点用不着
APACHE的高手们早为我们写了很多工具类
去开元下 jar包,解压后 看看readme
就像beanutils包
有三个jar
commons-beanutils.jar 185k
commons-beanutils-bean-collections.jar 26k
commons-beanutils-core 165k
其实第一个就是二三的集合
一是给 懒人用的
二三给 高手用,非常清楚知道自己想要什么。。。
普通APP加jar包别一上去就 ADD EXTERNAL JAR,
给人家考虑考虑,你ADD EXTERNAL JAR在自己电脑上没有问题
把程序给人家了就有问题了
人家电脑上哪里会在那个目录下有那个jar包啊???
好习惯是在 src 兄弟目录下 创建lib目录
考进去
再 右击 ADD TO BUILD PATH
看见一个小奶瓶就OK了
然后运行会 报错 一般都需要一个logging包,考过来就好了
N多框架都用到logging包
然后BeanUtils这个类的方法非常强大,也非常多,
没有必要多说了,还会自动类型转化
主要是为了J2EE web开发用的,里面的很多地方都是String
然后自己会转化
★还有一个很大的好处
BeanUtils.setProperty(point,"birthday.setTime","10000000");//错的
//我已经在里面添加一个java.util.Date birthday
// birthday有setTime方法
//JAVABEAN规范 ,就有time属性了。
所以可以这样写,
BeanUtils.setProperty(point,"birthday.time","10000000");//OK
支持
★点导航★N多点也可以
★★但是你在bean里一定一定得先new 出实例来,否则有空 异常
想想如果自己反射都麻烦啊,既然人家写好了这么好的代码
就用吧。。。。。。。。。。。。。。。。。
取值也可以 点 导航
System.out.println(BeanUtils.getProperty(pt1,"birthday.time"));
还可以 把一个对象的属性 copy 到另一个 对象的属性上
还可以把一个JAVABEAN的属性变MAP [牛啊]
也可以把一个MAP的东西 填到 JAVABEAN里 [灌注 populate]
--------------
JAVA 7 里可以这样定义MAP
Map map = {name:"hubin",age:109}; //hehe
-----------
新技术是解决老问题的
老问题用老办法很烦,所以有新技术了
除了BeanUtils
还有一个类
PropertyUtils
刚刚说了BeanUtils都用String,为J2EE服务
而PropertyUtils老老实实用真实的属性类型[是int就是int,不转String]
beanutils包确实非常强大!!!!!!!!!!!!!!!!
分享到:
相关推荐
Algorithm-Machine-Learning-for-Beginner-by-Python3.zip,斯克莱恩、坦索流。,算法是为计算机程序高效、彻底地完成任务而创建的一组详细的准则。
资源分类:Python库 所属语言:Python 资源全名:for-beginner-piano-0.3.1.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
以pygame 游戏模块,来学习Python 基础,每章一个游戏。让python基础学得牢,学得有意思!
神奇的perl-最佳PERL入门读物 非常好的入门资料
COCOS2d-X by Example Beginner-'s Guide
python_for_absolute_beginner-源码.rar
rails-beginner-s-guide是Rails 指导手册,帮组学习了解rails开发
CSES_PRACTICE-2021-Beginner-源码.rar
Hacking-Secret-Ciphers-with-Python-A-beginner-s-guide-to-cryptography-and-computer-programming-with-Python.pdf
Emacs-Beginner-HOWTO.pdf, 学习emacs的入门手册,希望对emacs迷们有用
Beginner-CPP-Programming-From-Beginner-to-Beyond
Covers the recent release of the Java 2 Platform Standard Edition 5.0 and the new J2SE Development Kit 5.0 * Starts with beginner topics including getting started with Java, using the Java ...
Beginner-Level COM Tutorial初学者COM指南
A list of beginner-friendly NLP projects—using pre-trained models,用预训练模型零基础体会最先进NLP技术,by Caleb Kaiser。
NumPy_1_5_Beginner__039_s_Guide-234页
introduce in english
Spring MVC is a model-view-controller framework for Java web applications to simplify the writing and testing of Java web applications, which fully integrates with the Spring dependency injection ...
the installation and basic usage, you will learn to use the administration interface for adding data, configuring layers, customizing OGC services, and securing your site. You will find included ...
制作复杂的windows批处理文件的教材
一个简单的用于建仓的信号灯指标