如何在spring xml上下文文件的属性中使用算术运算符

问题描述 投票:0回答:1

我有这段代码我试图让它工作。体育场总数是Team类中int类型的属性,它具有getter和setter方法。

我想使用算术运算符,但在值的语法中给出错误

<?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)"
spring spring-el
1个回答
3
投票

Spring 3.0附带Spring EL你可以使用它

  <property name="totalStadium" value="${2 * 3}"/> 
© www.soinside.com 2019 - 2024. All rights reserved.