• EL表达式(二)运算符


    运算符"."和"[]": "."能做的"[]"也能做,"[]"能做的"."不一定能做。java不识别的用"[]"

    算数运算符:+,-,*,/或div,%或mod
    关系运算符:==或eq,!=或ne,<或lt,>或gt,<=或le,>=或ge
    逻辑运算符: &&或and , ||或or , !或not
    其他运算符: empty 当判断的对象为null或空字符串否返回true,集合对象部位null,但无元素是返回true , ?: 三元运算符(${a?b:c})

    EL表达式不支持字符串链接

    1. Java 

     1 package cn.gs.ly.mvc.domain;
     2 
     3 import java.util.Date;
     4 
     5 public class Person {
     6     private String name;
     7     private String gender;
     8     private boolean married;
     9     private Date birthday;
    10     private Address address = new Address();
    11     
    12     public Person() {
    13         
    14     }
    15     
    16     public Person(String name, String gender, boolean married) {
    17         super();
    18         this.name = name;
    19         this.gender = gender;
    20         this.married = married;
    21     }
    22     
    23     
    24     public Address getAddress() {
    25         return address;
    26     }
    27 
    28     public void setAddres(Address address) {
    29         this.address = address;
    30     }
    31 
    32     public String getName() {
    33         return name;
    34     }
    35     public void setName(String name) {
    36         this.name = name;
    37     }
    38     public String getGender() {
    39         return gender;
    40     }
    41     public void setGender(String gender) {
    42         this.gender = gender;
    43     }
    44     public boolean isMarried() {
    45         return married;
    46     }
    47     public void setMarried(boolean married) {
    48         this.married = married;
    49     }
    50     public Date getBirthday() {
    51         return birthday;
    52     }
    53     public void setBirthday(Date birthday) {
    54         this.birthday = birthday;
    55     }
    56     
    57 }

    2. jsp

     1 <%@page import="java.util.HashMap"%>
     2 <%@page import="java.util.Map"%>
     3 <%@page import="java.util.ArrayList"%>
     4 <%@page import="java.util.List"%>
     5 <%@page import="cn.gs.ly.mvc.domain.Person"%>
     6 <%@ page language="java" contentType="text/html" pageEncoding="UTF-8"%>
     7 <!DOCTYPE html>
     8 <html>
     9 <head>
    10 <title>Insert title here</title>
    11 </head>
    12 <body>
    13     <%
    14         pageContext.setAttribute("num1", "100");
    15         pageContext.setAttribute("num2", "20");
    16     %>
    17     加法:${num1+num2 }<hr/>
    18     减法:${num1-num2 }<hr/>
    19     乘法:${num1*num2 }<hr/>
    20     除法:${num1/num2 }或${num1 div num2 }<hr/>
    21     取模:${num1%num2 }或${num1 mod num2 }<hr/>
    22     
    23     等于:${num1==num2 }或${num1 eq num2 }<hr/>
    24     不等于:${num1!=num2 }或${num1 ne num2 }<hr/>
    25     大于:${num1>num2 }或${num1 gt num2 }<hr/>
    26     小于:${num1<num2 }或${num1 lt num2 }<hr/>
    27     大于等于:${num1>=num2 }或${num1 ge num2 }<hr/>
    28     小于等于:${num1<=num2 }或${num1 le num2 }<hr/>
    29     
    30     实例化前:${empty p}<hr/>
    31     实例化前:${empty ""}<hr/>
    32     <jsp:useBean id="p" class="cn.gs.ly.mvc.domain.Person"></jsp:useBean>
    33     实例化后:${empty p}<hr/>
    34     实例化后:${empty ""}<hr/>
    35     实例化后:${empty " "}<hr/>
    36     
    37     <%
    38         List list = new ArrayList();
    39         list.add("a");
    40     
    41         pageContext.setAttribute("list", list);
    42         
    43         session.setAttribute("user", "liuchao");
    44         pageContext.setAttribute("gender", "0");// 0男1女
    45     %>
    46     list集合:${empty list }<hr/>
    47     user:${empty sessionScope.user?"请登录":"欢迎" }${user }<hr/>
    48     性别:${gender==0?"男":"女" }<hr/>
    49     
    50 </body>
    51 </html>

    3. 运行结果

  • 相关阅读:
    H5页面开发的touchmove事件
    css奇技淫巧—border-radius
    css奇技淫巧—box-shadow与outline绘制多重边框效果
    移动前端自适应解决方案和比较
    rem字体在rem盒子里面不一样,或者不同的行解决
    rem 回家测试
    js中函数提升及var变量提示
    盒子模型的百分比是根据什么来的
    $(function(){})返回值$(document)
    开发过程中错误总结
  • 原文地址:https://www.cnblogs.com/liuyangv/p/8195198.html
Copyright © 2020-2023  润新知