当前位置: 移动技术网 > IT编程>开发语言>Java > 使用SpringEL表达式进行三目运算

使用SpringEL表达式进行三目运算

2020年03月14日  | 移动技术网IT编程  | 我要评论

五侯山,农行猴年纪念币预约,混蛋神风流史txt

原文链接:http://www.yiidian.com/spring/spring-el-three-mesh-operator.html

spel支持三目运算符,以此来实现条件语句。

一、编写bean类

item类:

package com.yiidian.domain;
/**
 * 
 * @author http://www.yiidian.com
 *
 */
public class item {
    
    private int qtyonhand;
    public int getqtyonhand() {
        return qtyonhand;
    }
 
    public void setqtyonhand(int qtyonhand) {
        this.qtyonhand = qtyonhand;
    }
}

customer类:

package com.yiidian.domain;

import java.io.serializable;
/**
 * 
 * @author http://www.yiidian.com
 *
 */
public class customer implements serializable{
    private boolean warning;
    public boolean iswarning() {
        return warning;
    }
    public void setwarning(boolean warning) {
        this.warning = warning;
    }
 
    @override
    public string tostring() {
        return "customer [warning=" + warning + "]";
    }
}

二、配置applicationcontext.xml

<?xml version="1.0" encoding="utf-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:p="http://www.springframework.org/schema/p" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"
    xsi:schemalocation="
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
    
    <bean id="customer" class="com.yiidian.domain.customer">
        <property name="warning" value="#{itembean.qtyonhand &lt; 100 ? true : false}" />
    </bean>
 
    <bean id="itembean" class="com.yiidian.domain.item">
        <property name="qtyonhand" value="99" />
    </bean>


</beans>

三、编写测试类

package com.yiidian.test;

import org.junit.test;
import org.springframework.context.applicationcontext;
import org.springframework.context.support.classpathxmlapplicationcontext;

import com.yiidian.domain.customer;

/**
 * @author http://www.yiidian.com
 * 
 */
public class demo1 {

    @test
    public void test1() {
        applicationcontext context = new classpathxmlapplicationcontext("applicationcontext.xml");
        customer customer = (customer)context.getbean("customer");
        system.out.println(customer);
    }

}

四、运行结果

file

源码下载:http://pan.baidu.com/s/1qymlkfe
file

欢迎关注我的公众号::一点教程。获得独家整理的学习资源和日常干货推送。
如果您对我的系列教程感兴趣,也可以关注我的网站:

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网