EL表达式

EL表达式

Expression Language表达式语言,代替JSP页面中数据访问时的复杂编码,可以⾮常便捷地取出域对象(pageContext、request、session、application)中保存的数据,前提是⼀定要先 setAttribute,EL 就相当于在简化 getAttribute。

${变量名} 变量名就是 setAttribute 对应的 key 值。

<%
    String name=(String)request.getAttribute("name");
%>
<%=name%>
<hr/>
//EL表达式与上述一样,可以取出name值
${name}

1、EL 对于 4 种域对象的默认查找顺序:(优先级pageContext最高)
pageContext -》request-〉session-》application
按照上述的顺序进⾏查找,找到⽴即返回,在 application 中也⽆法找到,则返回 null。

2、指定作⽤域进⾏查找
pageContext: p a g e S c o p e . n a m e r e q u e s t : {pageScope.name} request: pageScope.namerequest{requestScope.name}
session: s e s s i o n S c o p e . n a m e a p p l i c a t i o n : {sessionScope.name} application: sessionScope.nameapplication{applicationScope.name}
数据级联:

<table>
    <tr>
        <th>编号</th>
        <th>姓名</th>
        <th>成绩</th>
        <th>地址</th>
    </tr>
    <tr>
<%--        注意:el表达式通过下面的方式获取,user.id不是通过user的id来获取值,而是通过getID()方法。先将id变为Id,再在前面加上get--%>
        <th>${user.id}</th>
<%--        <%--%>
<%--            ((User) pageContext.getAttribute("user")).getId();--%>
<%--        %>--%>
        <td>${user.name}</td>
        <td>${user.score}</td>
        <td>${user.address.value}</td>
    </tr>
</table>
package com.y.entity;

public class Address {
    private Integer id;
    private String value;

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }

    public Address(Integer id, String value) {
        this.id = id;
        this.value = value;
    }
}

package com.y.entity;

public class User {
    private Integer id;
    private String name;
    private  Double score;
    private Address address;
    public User(Integer id, String name, Double score) {
        this.id = id;
        this.name = name;
        this.score = score;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Double getScore() {
        return score;
    }

    public void setScore(Double score) {
        this.score = score;
    }
//重写

    public Address getAddress() {
        return address;
    }

    public void setAddress(Address address) {
        this.address = address;
    }

    public User(Integer id, String name, Double score, Address address) {
        this.id = id;
        this.name = name;
        this.score = score;
        this.address = address;
    }

}

EL 执⾏表达式
&& || ! < > <= >=.

${num1&&num2}
&& || ! < > <= <= ==

&& and
|| or
! not
== eq
!= ne
< lt

gt
<= le
= ge
empty 变量为 null,⻓度为0的String,size为0的集合

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值