A little more difficult problems, and ResultSet achieve similar

Category: Java SE
 
jiangxiabing
2013-08-20 04:29:01

Sponsored Links
The situation is this:

a bean
public class Student {
int id
String name;
int score;
String classname;
...

}
many attributes, to Set attribute can only set up one by one,
Student sd = new Student ()
sd.setId (xx)
sd.setscore (xx)
very troublesome .. and is not universal, if the bean to add a property, as long as you have all the code in place for such an assignment would bean write sd.setXXX (xxx);
I wanted to write such a generic method, Like ResultSet, able to use ResultSet.getString (int x) or Resultset.getString (String fieldname) in such a way you can get the desired properties, such as

StudentHelper.getString ("classname" ) ... Back classname
StudentHelper.getString (1) ... return id
is to get a class all of the variables and the classes in the order defined


Sponsored Links

Domain and server ip had changed since 8/23/2013. Suspend the user registration and posts for program maintenance.