Atitit.java assigned to the property value method and Beanutils 1.6.1. Copyproperty Bug
1. Core.setproperty (o, "materialid", null); 1
2. Java Reflection (Java reflection ) 1
3. Use of Reflection 2
4. classes required in the Java class reflection: 2
Beanutils.copyproperty 2
5. Beanutils.setproperty 2
6. References 4
1. Core.setproperty (o, "materialid", null);
BeanUtils1.6.1 Copyproperty Korean style setproperty have a bug ...
Yaosi prpty SHG Integer...,,sett null when the child does not efficiency , not a change to 0..def convertyeu prob l ....
Yanen reg custm Convert L. zeush pa effice Zaid code l ... zihao gazi write nwe d le ...
2. Java Reflection (Java reflection)
Reflection is one of the characteristics of the Java programming language, and it agrees to execute the Java program to check itself. or , " self-examination ." And can directly manipulate the internal properties of the program. For example, you can use it to get the names of the members in the Java class and display them.
Java of this capability may not be used very much in practical applications. But in other programming languages there is no such feature at all. Like what. There is no way in Pascal,c , or C + + to get information about function definitions in a program.
The concept of reflection was first proposed by Smith in 1982. The main point is the ability of a program to access, detect, and alter its own state or behavior. The proposal of this concept has aroused the research on the application of reflectivity in computer science very quickly. It was first used in the field of programming language design, and made achievements in Lisp and object-oriented. Among them, lead/lead++, openc++, Metaxa and Openjava are the language based on reflection mechanism.
Recently, the reflection mechanism has also been applied to the Windows system, the operating system and the file system.
Reflection itself is not a new concept. Although computer science gives a new meaning to the concept of reflection.
In the field of computer science. Reflection refers to a class of applications. They can self-describe narrative and self-control. Other words. Such applications use a mechanism to achieve descriptive narration (self-representation) and monitoring (examination) of their own behavior, and can be based on the state and results of their actions. Adjust or modify the state and related semantics of the descriptive behavior described in the application
Author:: Old Wow's paw attilax Ayron, email:[email protected]
Reprint please indicate source: Http://blog.csdn.net/attilax
3. Use of Reflection
JavaBean is One of the practical applications of reflection. It enables some tools to visualize the operating software components. These tools dynamically load and get Java Components ( classes ) through reflection 's Properties.
Most of the flexibility and scalability of the system is reflected and so on to load external plug-ins. Allows the system to decouple from the plug-in at the same time, adding functionality
4. JavaClasses that are required in class reflection:
There are not many classes required for class reflection in Java. Each of them is: Field, Constructor, Method, class, Object, and I'll make a brief description of these classes below.
Constructor class: Provides information about a single construction method of a class and access to it.
This class differs from the field class in that the field class encapsulates the properties of the reflection class. The constructor class encapsulates the construction method of the Reflection class.
The Setaccessible method of the Field class. It is used to set whether there is permission to access the private property in the reflection class, only if it is set to true when the ability to interview, the default is False. The field class also has the set (Object Attributename,object value) method, which can change the value of the specified property.
Beanutils.copyproperty5. Beanutils.setproperty
Beanutils.setproperty (java.lang.Object bean,java.lang.string name,java.lang.object value)
This method makes me depressed for a while, because it provides the function with the above said Beanutils.copyproperty (Java.lang.Object bean,java.lang.string name,java.lang.object Value), Apache's hero have no reason to offer two ways to display the same function, and then I looked at the Javadoc in Apache.commons.beanutils.BeanUtilsBean, Just a little bit clearer. Assuming that we only assign values to bean properties, we can use Copyproperty () and the SetProperty () method is the basis for implementing the Beanutils.populate () (later) mechanism. That is, assuming that we need to define our own implementation of the populate () method, then we can override the SetProperty () method.
Therefore, as a general daily use, the SetProperty () method is not recommended for use.
Beanutils.populate (Java.lang.Object Bean, Java.util.Map properties)
Use a map to assign a value to the bean, and the name of the key in the map corresponds to the member variable name in the bean. Note: The populate mechanism only works when the key and member variable names are fully relevant, but no matter what the number is, If the key assumption in the map is a subset of the member variable names, then some of the member variables and items not included in the map will retain the default values, and the same, assuming that the member variable is a subset of key in the map, then the extra key will not have any effect on the populate result. Yes, The result is that populate only works on the intersection of the key name set in the map and the member variable name set in the bean. (Very Laokou AH)
It is often very easy to use the method, here slightly off.
Similarly, this approach also supports single elements in an array, the assignment of individual elements and nested attributes in map, and the detailed approach and the Copyproperty () method, such as the following:
Values.put ("words[1]", "U");
Values.put ("Map (Home)", "remote");
Values.put ("Sample.display", New Double (5.0));
Note: In Apache's Javadoc, it is clear that this method is specifically defined and used for parsing HTTP request parameters and is not recommended for normal use. They recommend using the Beanutils.copyproperties () method. (The Formbean in struts should be assembled in this way)
Public static void SetProperty (Object obj , String propername, Object Val ) {
Try {
//beanutils.copyproperty (obj, Propername, val);
Field fld=obj. GetClass (). Getdeclaredfield (propername) ;
fld. setaccessible (True) ;
FLD . Set (obj, val) ;
// Beanutils.setproperty
} catch ( illegalaccessexception e ) {
// Attilax Old Wow's paw 8:23:56 PM Jul ,
Core . warn (e) ;
} catch (SecurityException e) {
// Attilax Old Wow's paw 11:15:33 PM Jul ,
e . Printstacktrace ();
} catch (nosuchfieldexception e) {
// Attilax Old Wow's paw 11:15:33 PM Jul ,
e . Printstacktrace ();
}
}
6. References
Beanutils Get object attribute value format - integrated programming - dimensional cubic network - computer knowledge and technology interactive exchange platform . htm (Ability to customize converter, only implement converter interface or inherit abstractconverter category)
Copyright notice: This article blog original article. Blogs, without consent, may not be reproduced.
Atitit.java Method Property Assignment and Beanutils 1.6.1. Copyproperty Bug