`

org.springframework.beans.BeanWrapperImpl 获取一个Bean的(非final)属性

    博客分类:
  • java
阅读更多

public class TestBeanWrapper {
 
 private final Map extendProperties = new HashMap();  //只初始化一次,不能指向另一个引用
 
 private BeanWrapperImpl beanWrapper;

 private PropertyDescriptor[] descriptors;

 private boolean hasReflected = false;

 public static void main(String[] args) {
  TestBeanWrapper tb=new TestBeanWrapper();
  tb.test();
 }
 
 void test(){
  BeanWrapperImpl bi=new BeanWrapperImpl(this);
  PropertyDescriptor[] alldescriptors=bi.getPropertyDescriptors();
  
  int length=alldescriptors.length;
  List list = new ArrayList();
  
  for (int i = 0; i < alldescriptors.length; i++) {
   if (alldescriptors[i].getReadMethod() != null
     && alldescriptors[i].getWriteMethod() != null) {
    list.add(alldescriptors[i]);
    System.out.println(alldescriptors[i].getDisplayName());  //显示这个类的实例属性
   }
  }
  PropertyDescriptor[] descriptors = (PropertyDescriptor[]) list
    .toArray(new PropertyDescriptor[0]);
  
 System.out.println(descriptors.length+" list.length="+list.size());
 }

 public BeanWrapperImpl getBeanWrapper() {
  return beanWrapper;
 }

 public void setBeanWrapper(BeanWrapperImpl beanWrapper) {
  this.beanWrapper = beanWrapper;
 }

 public PropertyDescriptor[] getDescriptors() {
  return descriptors;
 }

 public void setDescriptors(PropertyDescriptor[] descriptors) {
  this.descriptors = descriptors;
 }

 public boolean isHasReflected() {
  return hasReflected;
 }

 public void setHasReflected(boolean hasReflected) {
  this.hasReflected = hasReflected;
 }

 public Map getExtendProperties() {
  return extendProperties;
 }

 
}

分享到:
评论

相关推荐

    spring_MVC源码

    14. &lt;bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" /&gt; 15. 16. &lt;!-- 对模型视图名称的解析,即在模型视图名称添加前后缀 --&gt; 17. &lt;bean class="org....

    ssh(structs,spring,hibernate)框架中的上传下载

    数据表Blob字段在Hibernate持久化映射文件中的type为org.springframework.orm.hibernate3.support.BlobByteArrayType,即Spring所提供的用户自定义的类型,而非java.sql.Blob。 3在Spring中使用org.springframework...

    客户关系管理系统框架搭建(二)

    &lt;bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"&gt; &lt;!--表示在类路径下加载hibernate.cfg.xml --&gt; &lt;value&gt;classpath:hibernate.cfg.xml ...

    基于SpringMVC+Hibernate4的考勤管理系统+.zip

    spring-beans-4.0.0.RELEASE.jar 所有应用都要用到的,它包含访问配置文件、创建和管理bean spring-context-4.0.0.RELEASE.jar Spring 核心提供了大量扩展 spring-core-4.0.0.RELEASE.jar Spring 框架基本的核心工具...

    SpringMybatis:springMybatis多数据源

    SpringMybatis Spring / Mybatis多... org.springframework.beans.factory.NoSuchBeanDefinitionException:没有找到类型为[com.proto.net.aron.aronMapper]的合​​格Bean作为依赖项:至少应有1个有资格作为此依赖

    第24次课-1 Spring与Hibernate的整合

    HibernateCallback是一个接口,位于org.springframework.orm.hibernate3中。 该接口中只有一个方法doInHibernate(Session session)。 通常,程序中采用实现HibernateCallback的匿名内部类来获取HibernateCallback的...

    struts-2.5.2-all所有jar包

    aopalliance-1.0.jar, asm-3.3.jar, asm-commons-3.3.jar, asm-tree-3.3.jar, ...validation-api-1.1.0.Final.jar, velocity-1.7.jar, xmlpull-1.1.3.1.jar, xpp3_min-1.1.4c.jar, xstream-1.4.8.jar

    struts-2.5.10-all所有jar包

    log4j-api-2.7.jar,ognl-3.1.12.jar,org.apache.felix.framework-4.0.3.jar,org.apache.felix.main-4.0.3.jar,org.apache.felix.shell-1.4.3.jar,org.apache.felix.shell.tui-1.4.1.jar,org.osgi.compendium-4.0.0....

    springmvc-jdbcTemplate

    import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework....

    cms后台管理

    一 Jeecms安装过程 将解压后得到的jeecms-...&lt;bean id="freemarkerConfig" class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer"&gt; &lt;property name="freemarkerVariables"&gt; &lt;map&gt; …… ...

Global site tag (gtag.js) - Google Analytics