首页 > 其他分享 >EL表达式, JSTL, 获取map集合中key的value

EL表达式, JSTL, 获取map集合中key的value

时间:2022-11-24 14:02:32浏览次数:45  
标签:function EL map jBox value dataMap import id page


序言:今天在项目中使用了map存储list和普通对象,但是在jsp中显示的时候出来问题,后经查阅,终于解决,现在记录一下,以便以后查阅:

一:后台代码如下:

package cn.gov.csrc.cms.action;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import cn.gov.csrc.base.action.BaseAction;
import cn.gov.csrc.cms.model.RoleInfo;
import cn.gov.csrc.cms.service.RoleService;
import cn.gov.csrc.cms.util.PageData;
import cn.gov.csrc.cms.util.PageNavUtil;

import com.opensymphony.xwork2.ActionContext;

@Controller
@Scope("prototype")
public class RoleAction extends BaseAction<RoleInfo>{

private static Logger logger = LoggerFactory.getLogger(RoleAction.class);

private static final long serialVersionUID = 1L;

private Integer page;

private Map<String, Object> dataMap;

private RoleService roleService;

public RoleAction() {
dataMap = new HashMap<String, Object>();
}

@Resource
public void setRoleService(RoleService roleService) {
this.roleService = roleService;
}

@Action(value = "RoleAction_find", results={@Result(name = "success", location = "/ucenter/sys/roleList.jsp")})
public String find(){
page = page == null ? 1 : page < 1 ? 1:page;
int pageSize = 5;
PageData<RoleInfo> pageData = this.roleService.getRoles(page,pageSize,model.getRoleName());
dataMap.clear();
dataMap.put("dataList", pageData.getPageData());
dataMap.put("totalCount", pageData.getTotalCount());
dataMap.put("totalPage", pageData.getTotalPage());
dataMap.put("currentPage", page);
dataMap.put("pageNav", PageNavUtil.getPageNavHtml(page.intValue(), pageSize, pageData.getTotalCount(), 15));
ActionContext.getContext().getSession().put("dataMap", dataMap);
return "success";
}

public Integer getPage() {
return page;
}

public void setPage(Integer page) {
this.page = page;
}


}


二:前台jsp代码如下:

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ include file="../../common/include_tag.jsp"%>
<%@ include file="../../common/page_var.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><%=pageTitle%> - 角色管理</title>
<%@ include file="../../common/page_head.jsp"%>
<script type="text/javascript">
function add(){
$.jBox("iframe:#.action", {
title: "添加角色",
width: 700,
height: 320,
buttons: {}
});
}

function edit(id){
$.jBox("iframe:#.action?id="+id, {
title: "修改角色",
width: 700,
height: 320,
buttons: {}
});
}

function delRole(id,msg){
$.jBox.confirm("确定删除 ["+msg+"] 角色吗?", "确认操作", function (v, h, f) {
if (v == 'ok'){
$.post("#.action",{id:id},function(responseText){
if(responseText==true){
$.jBox.info("操作成功,请刷新查看结果", "成功信息",{top: '20%'});
}else{
$.jBox.error("操作失败", "失败信息");
}
});
}
return true;
},{top: '40%'});
}

function changeRoleStatus(id,status){
$.jBox.confirm("确定 "+(status==0?"禁用":"启用")+" 用户吗?", "确认操作", function (v, h, f) {
if (v == 'ok'){
$.post("#.action",{id:id,status:status},function(responseText){
if(responseText==true){
$.jBox.info("操作成功,请刷新查看结果", "成功信息",{top: '20%'});
}else{
$.jBox.error("操作失败", "失败信息");
}
});
}
return true;
},{top: '40%'});
}

function roleResourceSet(roleId){
$.jBox("iframe:#.action?roleId="+roleId, {
title: "角色资源授权",
width: 700,
height: 550,
buttons: {}
});
}

$().ready(function(){
pilicat.alternately('list');
});
</script>
</head>
<body>
<div style="height: 60px; overflow: hidden">
<%@ include file="../u_top.jsp"%>
</div>
<div id="frame_side">
<%@ include file="../u_login_info.jsp"%>
<jsp:include page="../u_left_menu.jsp" flush="true">
<jsp:param name="current" value="roles" />
</jsp:include>
</div>
<div id="body_box">
<table cellpadding="0" cellspacing="0" border="0" class="icon">
<tr>
<td></td>
</tr>
</table>
<span style="text-align: left;padding-left: 10px;">系统管理 -> 角色管理 -> 角色列表</span>
<table cellpadding="0" cellspacing="0" border="0" class="table">
<tbody>
<tr>
<td valign="top" align="right">
<form action="" method="get" name="search" id="search">
<table cellpadding="0" cellspacing="5" border="0">
<tbody>
<tr>
<td><a class="button_4" href="javascript:;" οnclick="add();">添加新角色</a></td>
</tr>
</tbody>
</table>
</form>
</td>
</tr>
</tbody>
</table>
<div class="rounded table">
<form action="" method="get" name="search_form" id="search_form">
<table width="100%" cellpadding="0" cellspacing="0" border="0"
class="box_top">
<tr>
<td class="title">角色列表</td>
<td></td>
</tr>
</table>
</form>

<form action="" method="post" name="manage" id="manage">
<table class="list td_align" cellpadding="0" cellspacing="1"
border="0">
<tr>
<td class="field_head" width="30">选择</td>
<td class="field_head">角色ID</td>
<td class="field_head">角色名称</td>
<td class="field_head">角色描述</td>
<td class="field_head">操作</td>
</tr>
<c:forEach items="${dataMap.dataList}" var="dataItem" varStatus="rowStatus">
<tr>
<td><input type="checkbox" name="cbitem" value="${dataItem.id }" /></td>
<td>${dataItem.id}</td>
<td>${dataItem.roleName}</td>
<td>${dataItem.roleDesc}</td>
<td class="operation"><a href="javascript:;"
οnclick="edit(${dataItem.id});"> <img
src="./css/images/operation/pencil.png"
title="修改角色信息" />
</a> <a href="javascript:;"
οnclick="roleResourceSet(${dataItem.id});"> <img
src="./css/images/operation/folder.png"
title="角色权限" />
</a> <a href="javascript:;"
οnclick="delRole(${dataItem.id},'${dataItem.roleName}');"> <img
src="./css/images/operation/trashcan_delete.png"
title="删除角色" />
</a></td>
</tr>
</c:forEach>
</table>
<table class="table top_line">
<tr>
<td>
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td class="all_action"><input name="allChkbox"
id="allChkbox" type="checkbox"
οnclick="pilicat.select_all(this.form);" /></td>
<td> 全选/取消 </td>
<td class="operation"></td>
</tr>
</table>
</td>
</tr>
</table>
</form>
<table class="page" cellpadding="0" cellspacing="5">
<tr>
<td>
<div id="pageNav" class="scott">
<font color="#88af3f">共${dataMap["totalCount"]} 条数据, ${dataMap["totalPage"]} 页</font>
${dataMap["pageNav"]}
</div>
</td>
</tr>
</table>
</div>
<%@ include file="../u_bottom.jsp"%>
</div>
</body>
</html>


注:主要是下面的分页显示:

<div id="pageNav" class="scott">
<font color="#88af3f">共${dataMap["totalCount"]} 条数据, ${dataMap["totalPage"]} 页</font>
${dataMap["pageNav"]}
</div>

标签:function,EL,map,jBox,value,dataMap,import,id,page
From: https://blog.51cto.com/u_4679008/5883755

相关文章

  • org.apache.commons.fileupload.FileUploadBase$SizeLimitExceededException:
    一:今天在使用struts2做文件上传时出现了该异常:警告:Unabletoparserequestorg.apache.commons.fileupload.FileUploadBase$SizeLimitExceededException:therequestwas......
  • EL表达式和JSTL标签快速入门
    <%Stringdata="mydata";request.setAttribute("data",data);%>${data}<%--pageContext.findAttribute("data")pagerequestsessionapplica......
  • Thymeleaf学习
    Thymeleaf学习三大模板jsphtmlthymeleaftldfreemarker面试题:什么是模板,为什么使用thymeleaf模板?第一,Thymeleaf在有网络和无网络的环境下皆可运行,......
  • element ui 中引入自定义的图标
    1.去iconfont里找到要用的图标并加入到项目中2.在项目页面点击项目设置 按如图修改3.修改后保存 下载到本地4.在main.js中引入下载的 iconfont.css(在i......
  • ElGamal的安全性
    ElGamal的安全性ElGamal密码体制基于离散对数问题。离散对数问题离散对数问题(DLP)已知一个乘法群\((G,\cdot)\),一个\(n\)阶元素\(\alpha\inG\)和元素\(\beta\inG......
  • kotlin类似javalist map所谓c shape 或ios那边的字典的遍历循环和创建以及泛型
    println("testlengthfunc:${getObjectLength("Howlongdoihave,please?")}");//geLength会出现会重写的情况,应该是自动倒入了某些系统的类导致的。varlist=li......
  • electron 本地及打包后获取的路径
    electron本地及打包后获取的路径 //打印//本地//打包安装co......
  • selenium自动化基础知识
    等待1.显示等待显示等待是单独针对某个元素,设置一个等待时间如5秒,每个0.5秒检查一次元素是否出现,如果在五秒之前任何时候出现,则继续向下执行,超过五秒尚未出......
  • [原创]shell创建文件或者文件夹快捷方式到桌面的脚本shell
    刚开始学shell编程写的#!/bin/bashvartest='我是变量,变量读取和gradle类似,用${}访问'echo变量长度${#vartest}echo"支持直接不输入引号echo,"#为毛直接显示了。'$e{,ee......
  • v-model修饰符
    v-model.lazy(等到输入框回车或者失去焦点的时候再改变数据)v-model.number(一般data传过来的都是字符串,你想要input的type是number,那就需要加上这个修饰符)v-model.tri......