如何在 spring xml 上下文文件的 属性 中使用算术运算符
How to use arithmetic operator in property of spring xml context files
我有这段代码,我正在努力让它发挥作用。 Total stadium是class Team中的一个属性 int类型,它有getters和setters方法。
我想使用算术运算符,但在值的语法中给出了错误
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<bean id="nameId" class="com.valentine.Namer">
<property name="name">
<value>java-beat</value>
</property>
</bean>
<!--teams-->
<bean id="nigeriaId" class="com.valentine.Team">
<property name="name">
<value>nigeria</value>
</property>
<property name="players">
<set>
<ref bean="mikel"/>
<ref bean="john"/>
<ref bean="kaita"/>
</set>
</property>
<property name="totalStadium" value="$(2 * 3)"/> // iget an error here cannot compile or accept syntax
</bean>
我做错了什么?先感谢您。
这是我收到的错误
Caused by: org.springframework.beans.TypeMismatchException: Failed to convert property value of type 'java.lang.String' to required type 'int' for property 'totalStadium'; nested exception is java.lang.NumberFormatException: For input string: "$(2*3)"
Spring3.0自带SpringEL你可以用这个
<property name="totalStadium" value="${2 * 3}"/>
我有这段代码,我正在努力让它发挥作用。 Total stadium是class Team中的一个属性 int类型,它有getters和setters方法。
我想使用算术运算符,但在值的语法中给出了错误
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<bean id="nameId" class="com.valentine.Namer">
<property name="name">
<value>java-beat</value>
</property>
</bean>
<!--teams-->
<bean id="nigeriaId" class="com.valentine.Team">
<property name="name">
<value>nigeria</value>
</property>
<property name="players">
<set>
<ref bean="mikel"/>
<ref bean="john"/>
<ref bean="kaita"/>
</set>
</property>
<property name="totalStadium" value="$(2 * 3)"/> // iget an error here cannot compile or accept syntax
</bean>
我做错了什么?先感谢您。 这是我收到的错误
Caused by: org.springframework.beans.TypeMismatchException: Failed to convert property value of type 'java.lang.String' to required type 'int' for property 'totalStadium'; nested exception is java.lang.NumberFormatException: For input string: "$(2*3)"
Spring3.0自带SpringEL你可以用这个
<property name="totalStadium" value="${2 * 3}"/>