EL(Expressin Language)表达式

本文详细介绍了EL(Expression Language)表达式在JSP页面中的使用,包括语法、解决EL不显示的问题、.与[]的区别、Map属性获取、关系逻辑运算符、empty运算符以及JSPEL的隐含对象。通过示例展示了如何在表达式中使用这些对象,如${requestScope.student}

EL(Expressin Language)表达式

可以代替jsp页面中的java代码

1)语法

${requestScope.student}
域对象

2)el语句不显示(配置不完整,系统忽略了EL表达式)

解决方案
1.
<%@ page isELIgnored="false" %>
2.
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
 
 
</web-app>

3).和[]的区别

====.操作符===
${requestScope.student}
=======[]操作符======<br>
<%--单引号,双引号都可以--%>
${requestScope["student"]["address"]}
[]可以获取数组,变量,特殊符号

4)获取map属性

        Map<String,Object> map = new HashMap<>();
        map.put("cn","中国");
        map.put("us","美国");
        req.setAttribute("map",map);
        req.getRequestDispatcher("elmap.jsp").forward(req,resp);
        
        ${requestScope.map.cn}
		${requestScope.map["us"]}

5)关系逻辑运算符

${2>1}
${!true}
${5+6}

6)empty运算符

${empty requestScope["my-name"]}

7)隐式对象

JSP EL隐含对象

JSP EL支持下表列出的隐含对象:

隐含对象描述
pageScopepage 作用域
requestScoperequest 作用域
sessionScopesession 作用域
applicationScopeapplication 作用域
paramRequest 对象的参数,字符串
paramValuesRequest对象的参数,字符串集合
headerHTTP 信息头,字符串
headerValuesHTTP 信息头,字符串集合
initParam上下文初始化参数
cookieCookie值
pageContext当前页面的pageContext

您可以在表达式中使用这些对象,就像使用变量一样。接下来会给出几个例子来更好的理解这个概念。

${pageContext.request}-----》${pageContext.getRequest}
<%--级联--%>
${pageContext.request.serverPort}
// DeviceInfoMapper.java /* * Copyright 2019-2025 Zheng Jie * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package me.zhengjie.gen.service.mapstruct; import cn.hutool.core.util.StrUtil; import cn.hutool.json.JSONObject; import cn.hutool.json.JSONUtil; import me.zhengjie.gen.service.dto.DeviceInfoDto; import me.zhengjie.base.BaseMapper; import me.zhengjie.gen.domain.DeviceInfo; import me.zhengjie.gen.domain.DeviceModelTemplatePO; import me.zhengjie.gen.domain.ImageInfoPO; import me.zhengjie.service.S3StorageService; import org.mapstruct.Mapper; import org.mapstruct.Mapping; import org.mapstruct.ReportingPolicy; import java.util.Map; /** * @website https://eladmin.vip * @author chen jiayuan * @date 2025-09-16 **/ @Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE) public interface DeviceInfoMapper extends BaseMapper<DeviceInfoDto, DeviceInfo> { /** * 将 DeviceInfo、DeviceModelTemplatePO 和 ImageInfoPO 映射为 DeviceInfoDto * @param deviceInfo 设备信息 * @param template 设备模板信息 * @param imageInfo 镜像信息 * @return DeviceInfoDto */ @Mapping(source = "deviceInfo.id", target = "id") @Mapping(source = "deviceInfo.model", target = "model") @Mapping(source = "deviceInfo.country", target = "country") @Mapping(source = "deviceInfo.modelVersion", target = "modelVersion") @Mapping(source = "deviceInfo.status", target = "status") @Mapping(source = "deviceInfo.createdAt", target = "createdAt") @Mapping(source = "deviceInfo.updatedAt", target = "updatedAt") // 映射模板信息 @Mapping(source = "template.hwVersion", target = "hwVersion") @Mapping(source = "template.version", target = "version") @Mapping(source = "template.controllerVersion", target = "controllerVersion") @Mapping(source = "template.minControllerVersion", target = "minControllerVersion") @Mapping(source = "template.notSupportControllerVersion", target = "notSupportControllerVersion") @Mapping(source = "template.type", target = "type") @Mapping(source = "template.modelType", target = "modelType") @Mapping(source = "template.ippt", target = "ippt") @Mapping(source = "template.adoptResp", target = "adoptResp") // 映射镜像信息 @Mapping(source = "imageInfo.imageName", target = "imageName") @Mapping(source = "imageInfo.imgBucketPathMap", target = "imgBucketPathMap") DeviceInfoDto toDto(DeviceInfo deviceInfo, DeviceModelTemplatePO template, ImageInfoPO imageInfo); // 添加一个辅助方法用于处理 imgBucketPathMap 的拆分映射 default DeviceInfoDto toDtoWithImagePaths(DeviceInfo deviceInfo, DeviceModelTemplatePO template, ImageInfoPO imageInfo) { DeviceInfoDto dto = toDto(deviceInfo, template, imageInfo); // 拆分 imgBucketPathMap 字符串并转为 Map,再提取四个字段 if (imageInfo != null && imageInfo.getImgBucketPathMap() != null) { Map<String, String> imgBucketPathMap = imageInfo.getImgBucketPathMap(); String smallImgBucketPathForWeb = imgBucketPathMap.get("small_img_bucket_path_for_web"); String heatmapImgBucketPathForWeb = imgBucketPathMap.get("heatmap_img_bucket_path_for_web"); String bigImgBucketPathForWeb = imgBucketPathMap.get("big_img_bucket_path_for_web"); String hdpiImgBucketPathForApp = imgBucketPathMap.get("hdpi_img_bucket_path_for_app"); dto.setSmallImgBucketPathForWeb(smallImgBucketPathForWeb); dto.setHeatmapImgBucketPathForWeb(heatmapImgBucketPathForWeb); dto.setHdpiImgBucketPathForApp(hdpiImgBucketPathForApp); dto.setBigImgBucketPathForWeb(bigImgBucketPathForWeb); // 创建临时url返回前端 //generatePresignedUrl(smallImgBucketPathForWeb) } return dto; } } 修改这个代码,使得adot_resp从Map转为String,notSupportedVersion从List转为String
10-11
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值