The name of the parameter to be passed when using this method must end with the line number, minus the line number is the property name, such as page Pass Name+rowno, then the property name of the entity object should be name. The code is as follows
Get page data, automatically encapsulated as Bean object public List getobjectlist (Class clazz,string[] rownos) throws Exception{list objlist = new ArrayList (); for (int i=0;rownos!=null && i<rownos.length;i++) {//Create an object instance objects = Clazz.newinstance ();// Gets the properties of the class declaration field[] fields = Clazz.getdeclaredfields (); StringBuffer buffer = null;//Traversal property, performing encapsulation for (int j=0;j<fields.length;j++) {//Gets the name of the property string fieldName = Fields[j]. GetName ();//Gets the name of the parameter string paraname = Fields[j].getname () +rownos[i];//If the Get parameter value is empty then continue looping string value = Getvaluenull ( Paraname); if (value==null) {continue;} Parameter value object[] paramvalue =new object[1];if (Fields[j].gettype (). toString (). Equals ("Class java.lang.String")) { Paramvalue[0]=value;} if (Fields[j].gettype (). toString (). Equals ("Class Java.lang.Integer")) {paramvalue[0]=new Integer (value);} if (Fields[j].gettype (). toString (). Equals ("Class Java.lang.Double")) {paramvalue[0]=new Double (value);} if (Fields[j].gettype (). toString (). Equals ("Class Java.util.Date")) {SimpleDateFormat SDF = new SimpleDateFormat (" Yyyy-mm-dD ");p Aramvalue[0]=sdf.parse (value);} Parameter type class[] paramtype= {fields[j].gettype ()}; Get the name of the Set method buffer = new StringBuffer ("set"); Buffer.append (fieldname.substring (0, 1). toUpperCase ()); Buffer.append (fieldname.substring (1)); Get put back method = Clazz.getdeclaredmethod (Buffer.tostring (), paramtype); Execution Method Method.invoke (Object,paramvalue);} Places the current object in the list Objlist.add (object);} Return objlist;}
Automatically encapsulates a solid object with reflection