Detailed description of the instances in the JSP Spring configuration file, spring configuration file

Source: Internet
Author: User

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!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.