Home > Web Front-end > JS Tutorial > Detailed explanation of examples of passing values ​​in JSP Spring configuration files

Detailed explanation of examples of passing values ​​in JSP Spring configuration files

韦小宝
Release: 2018-01-18 09:50:19
Original
1425 people have browsed it

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; 
  } 
 
}
Copy after login

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" />
Copy after login

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; 
  } 
 
}
Copy after login

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>
Copy after login

Access the Filed property of the class

Java code:

public class Test3 { 
  public String name = "nihao"; 
  public static final int MAX_LENGTH = 10; 
}
Copy after login

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" />
Copy after login

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" />
Copy after login

Calling class method

Java code:

public class Test3 { 
  public void execute(String str, int i) { 
    System.err.println(str + "--" + i); 
  } 
}
Copy after login

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>
Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template