SpEL表达式简单使用

本文介绍了Spring的SpEL表达式,包括其用途、基本格式,并通过实例展示了如何进行简单参数、复杂参数以及带有表达式的传递。详细讨论了lt、gt等比较符的使用,同时提供了相关配置文件和代码示例。
摘要由CSDN通过智能技术生成

SpEL表达式简单使用

1.介绍

格式:
#{}
在Spring中有${}和SpEL表达式相似,

参考文档:
官网地址:https://docs.spring.io/spring/docs/4.3.28.RELEASE/spring-framework-reference/htmlsingle/
pdf下载:
链接:https://pan.baidu.com/s/1C2c18oEiHpluYNrifdoHnQ
提取码:su1w
在这里插入图片描述

2.使用

2.1 简单参数传递

  1. 给一个类中的Double类型字段传递参数
    #{5.0}
public class Bean1 {
    private Double num;
    public void setNum(Double num) {
        this.num = num;
    }
    public Double getNum() {
        return num;
    }
}

demo1.xml配置

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       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 name="bean1" class="com.example.Bean1">
            <property name="num" value="#{5.0}"></property>
        </bean>
</beans>

测试类Demo1

public class Demo1 {
    public static void main(String[] args) {
        Cla
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值