protected <T> String getCountField(Class<T> clazz){
String out = "o";
try {
PropertyDescriptor[] propertyDescriptors = Introspector.getBeanInfo(clazz).getPropertyDescriptors();
for(PropertyDescriptor propertydesc : propertyDescriptors){
Method method = propertydesc.getReadMethod();
if(method!=null && method.isAnnotationPresent(EmbeddedId.class)){
PropertyDescriptor[] ps = Introspector.getBeanInfo(propertydesc.getPropertyType()).getPropertyDescriptors();
out = "o."+ propertydesc.getName()+ "." + (!ps[1].getName().equals("class")? ps[1].getName(): ps[0].getName());
break;
}
}
} catch (Exception e) {
e.printStackTrace();
}
return out;
}
String out = "o";
try {
PropertyDescriptor[] propertyDescriptors = Introspector.getBeanInfo(clazz).getPropertyDescriptors();
for(PropertyDescriptor propertydesc : propertyDescriptors){
Method method = propertydesc.getReadMethod();
if(method!=null && method.isAnnotationPresent(EmbeddedId.class)){
PropertyDescriptor[] ps = Introspector.getBeanInfo(propertydesc.getPropertyType()).getPropertyDescriptors();
out = "o."+ propertydesc.getName()+ "." + (!ps[1].getName().equals("class")? ps[1].getName(): ps[0].getName());
break;
}
}
} catch (Exception e) {
e.printStackTrace();
}
return out;
}
解决方案 »
- 我不知道哪里错了。。
- SSH 查询所有数据的测试类 报空指针 求指教
- JBOSS启动失败,急急急!!!
- 新手问一个比较弱智的问题
- j2ee系统 点击登录后,点浏览器后退按钮又回到登录页面,然后再点前进又进入系统,这样很不安全
- jbpm-bpel-1.1.GA附带实例在jboss-4.2.2.GA上发布错误
- "No action config found for the specified url"的错误
- 请问LINUX下Mysql的JDBC驱动该如何设置 ?
- 为什么会出现错误: java.rmi.AccessException: CORBA NO_PERMISSION 0 No; nested exception
- 关于文件操作的两个小问题~!***在线关注,马上给分***
- 求一动态修改数据库表结构Demo
- 问一个设计思路
String out = "o";
try {
PropertyDescriptor[] propertyDescriptors = Introspector.getBeanInfo(clazz).getPropertyDescriptors();
for(PropertyDescriptor propertydesc : propertyDescriptors){
Method method = propertydesc.getReadMethod();
if(method!=null && method.isAnnotationPresent(EmbeddedId.class)){
PropertyDescriptor[] ps = Introspector.getBeanInfo(propertydesc.getPropertyType()).getPropertyDescriptors();
out = "o."+ propertydesc.getName()+ "." + (!ps[1].getName().equals("class")? ps[1].getName(): ps[0].getName());
break;
}
}
} catch (Exception e) {
e.printStackTrace();
}
return out;
}
String out = "o";
try {
PropertyDescriptor[] propertyDescriptors = Introspector.getBeanInfo(clazz).getPropertyDescriptors(); //拿到clazz类的所有属性的描述
for(PropertyDescriptor propertydesc : propertyDescriptors){ //遍历这个描述器数组
Method method = propertydesc.getReadMethod(); //拿到读取这个属性的方法。
if(method!=null && method.isAnnotationPresent(clazz)){
PropertyDescriptor[] ps = Introspector.getBeanInfo(propertydesc.getPropertyType()).getPropertyDescriptors(); //拿到属性类型的所有属性的描述
out = "o."+ propertydesc.getName()+ "." + (!ps[1].getName().equals("class")? ps[1].getName(): ps[0].getName()); //这个应该可以看懂
break;
}
}
} catch (Exception e) {
e.printStackTrace();
}
return out;
}