Exception in thread "main" java.beans.IntrospectionException: Method not found: isWBLDINST
2016-06-08 17:38
627 查看
今天做java的项目时
想通过反射为sql查询出的数据进行封装,结果一直报错
Exception in thread "main" java.beans.IntrospectionException: Method not found: isWBLDINST
at java.beans.PropertyDescriptor.<init>(Unknown Source)
at java.beans.PropertyDescriptor.<init>(Unknown Source)
at GetSet.testRef(GetSet.java:10)
at GetSet.main(GetSet.java:19)
但是我的WBLDINST用Eclipse自动生成了get和set方法
后来写个demo调试才发现原来是字段名大小写不一样导致的。
想通过反射为sql查询出的数据进行封装,结果一直报错
Exception in thread "main" java.beans.IntrospectionException: Method not found: isWBLDINST
at java.beans.PropertyDescriptor.<init>(Unknown Source)
at java.beans.PropertyDescriptor.<init>(Unknown Source)
at GetSet.testRef(GetSet.java:10)
at GetSet.main(GetSet.java:19)
但是我的WBLDINST用Eclipse自动生成了get和set方法
后来写个demo调试才发现原来是字段名大小写不一样导致的。
import java.beans.PropertyDescriptor; import java.lang.reflect.Field; import java.lang.reflect.Method; public class GetSet { public static <T>void testRef(Class<T> clazz) throws Exception{ T obj = clazz.newInstance(); Field[] fields = clazz.getDeclaredFields(); for(Field field : fields){ PropertyDescriptor descriptor = new PropertyDescriptor("WBLDINST", clazz); Method method = descriptor.getWriteMethod(); System.out.println(method.getName()); method.invoke(obj, "12"); } } public static void main(String[] args) throws Exception { // String s = "desc"; // System.out.println("set" + (s.toUpperCase().charAt(0)) + s.substring(1)); testRef(A.class); } } class A { private String name; private String wbldInst; public String getName() { return name; } public void setName(String name) { this.name = name; } public String getWbldInst() { return wbldInst; } public void setWbldInst(String wbldInst) { this.wbldInst = wbldInst; } }
相关文章推荐
- 在JAVA中如何跳出当前的多重嵌套循环
- Java中出现No enclosing instance of type XXX is accessible问题
- @NotEmpty、@NotBlank、@NotNull
- spring中MessageSource的配置使用方法--ResourceBundleMessageSource
- java关键字Transient
- 在Eclipse中创建Maven多模块工程的例子
- java中short s1 = 1;s1 = s1 + 1;会出错而short s1+=1;能编译通过的原因
- 使用CXF和spring搭建webService服务
- SpringMVC框架中的过滤器设置
- Spring整合Hessian
- java中断机制
- Java BIO、NIO、AIO
- Java设计模式
- eclipse/myeclipse中如何开启断言调试代码
- SpringMVC对静态资源进行缓存
- Java之Volatile关键字
- java 下载 通用contentType
- 对象引用与对象的区别
- Spring mvc 访问静态资源的三种方法
- Spring MVC视图解析器:配置多个视图解析器的优先级