Detailed description of the instances in the JSP Spring configuration file, spring configuration file
Detailed description of the instances in the JSP Spring configuration file
Use spring to provide a method to retrieve the passed value in the configuration file
Call the get Method
TargetObject: Specifies the called object.
PropertyPath: Specifies the getter method to be called.
Example 1:
public class Test1 { private String name = "nihao"; public String getName() { return name; } }
Xml Code
<bean id="t1" class="i.test.Test1" /> <!-- name = t1.getName() --> <bean id="name" class="org.springframework.beans.factory.config.PropertyPathFactoryBean" p:targetObject-ref="t1" p:propertyPath="name" />
Example 2:
Java code
public class Test3 { private Test1 t1 = new Test1(); private String name; public void setName(String name) { this.name = name; } public Test1 getT1() { return t1; } }
Xml Code
<! -- Assign the name attribute value of t1 to name of t3 --> <bean id = "t3" class = "I. test. Test3"> <property name = "name"> <! -- Run t3.getT1 (). getName () --> <bean id = "t3.t1. name "class =" org. springframework. beans. factory. config. propertyPathFactoryBean "/> </property> </bean>
Filed attribute of category
Java code
public class Test3 { public String name = "nihao"; public static final int MAX_LENGTH = 10; }
Xml Code
<Bean id = "t3" class = "I. test. Test3"/> <! -- An instance is required to access the Field of a member --> <bean id = "name" class = "org. springframework. beans. factory. config. fieldRetrievingFactoryBean "p: targetObject-ref =" t3 "p: targetField =" name "/>
Xml Code
<! -- Only the class path is required to access the static field --> <bean id = "length" class = "org. springframework. beans. factory. config. fieldRetrievingFactoryBean "p: targetClass =" I. test. test3 "p: targetField =" MAX_LENGTH "/> <! -- Or --> <bean id = "length" class = "org. springframework. beans. factory. config. fieldRetrievingFactoryBean "p: staticField =" I. test. test3.MAX _ LENGTH "/>
Method of the call class
Java code
public class Test3 { public void execute(String str, int i) { System.err.println(str + "--" + i); } }
Xml Code
<bean id="t3" class="i.test.Test3" /> <bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean" p:targetObject-ref="t3" p:targetMethod="execute"> <property name="arguments"> <list> <value>nihao</value> <value>56</value> </list> </property> </bean>
The above is an example of the value transfer in the JSP Spring configuration file. There are many articles on JSP Spring development on this site. If you have any questions, please leave a message or go to the community on this site for discussion. Thank you for reading, I hope to help you. Thank you for your support for this site!