Home > Article > Web Front-end > Detailed explanation of examples of passing values in JSP Spring configuration files
This article mainly introduces JSP SpringConfiguration fileRelated JSP information with detailed examples of passed values. Friends who are interested in JSP can refer to this article.
Detailed explanation of examples of passing values in JSP Spring configuration files
Use spring to provide methods to get passed values in configuration files
Call the get method
TargetObject: Specify the object to be called
PropertyPath: Specify which getter method to call
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:
<!-- 将t1的name属性值赋给t3的name --> <bean id="t3" class="i.test.Test3"> <property name="name"> <!-- 执行t3.getT1().getName() --> <bean id="t3.t1.name" class="org.springframework.beans.factory.config.PropertyPathFactoryBean" /> </property> </bean>
Access the Filed property of the class
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" /> <!-- 访问成员Field 需要实例 --> <bean id="name" class="org.springframework.beans.factory.config.FieldRetrievingFactoryBean" p:targetObject-ref="t3" p:targetField="name" />
Xml Code:
<!-- 访问静态field只需要类路径 --> <bean id="length" class="org.springframework.beans.factory.config.FieldRetrievingFactoryBean" p:targetClass="i.test.Test3" p:targetField="MAX_LENGTH" /> <!-- 或者 --> <bean id="length" class="org.springframework.beans.factory.config.FieldRetrievingFactoryBean" p:staticField="i.test.Test3.MAX_LENGTH" />
Calling class method
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 article about examples of value transfer in JSP Spring configuration files. There are many articles about JSP Spring development on this site. I hope it will be helpful to everyone's learning! !
Related recommendations:
jsPlumb flow chart experience summary
Declaration and usage instructions of variables and methods in jsp
JSP export Excel table example detailed explanation
The above is the detailed content of Detailed explanation of examples of passing values in JSP Spring configuration files. For more information, please follow other related articles on the PHP Chinese website!