public class goods{
Private String Goodsname;
Private String attr1;
Private String attr2;
Private String ATTR3;
Private String ATTR4;
.........
Private String Attr20;
Setter/getter method
}
In database table goods, the number of attributes of the product is known to be N (satisfies: N=5,ATTR1-ATTR5 has a value, Attr6-attr20 is empty). Ask how to remove the attribute values for each item:
Method One:
Remove the 20 attribute value
String attr1=goods.getattr1 ();
String attr2=goods.getattr2 ();
........
String Attr20=goods.getattr20 ();
Method Two:
Use reflection to take a value from a method name
Attr= Goods.getdeclaredmethod ("attr" +i);
The reflective knowledge involved, please consult other information, here only the dynamic product attribute value of the scheme.
Java reflection: The dynamic call method according to the method name, solve the commodity dynamic property value problem.