分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 教程案例

帆软报表和jeecg的进一步整合--ajax给后台传递map类型的参数

发布时间:2023-09-06 01:23责任编辑:顾先生关键词:暂无标签

下面是页面代码:

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%><%@include file="/context/mytags.jsp"%><%String deptIds = (String)request.getAttribute("departIds");String dic="t_s_depart";if(!"".equals(deptIds)){ ???dic="t_s_depart where ID in ("+deptIds+")";}%><t:base type="jquery,easyui,tools,DatePicker"></t:base><html> <head> ?<title>FineReport Demo</title> ?<script src = "webpage/xiaohaojiao/date.js"></script> ?????<script type="text/javascript"> ???$(document).ready(function(){ ???????$("#dept").change(function(){ ?????????????$("#department").val($(this).val()); ???????}); ???????//给时间控件加上样式 ???????$("#dates").click(function(){WdatePicker({dateFmt:‘yyyy-MM-dd‘});}); ???????$("#datez").click(function(){WdatePicker({dateFmt:‘yyyy-MM-dd‘});}); ???????getFineReport(); ???}); ???function getFineReport() { ???????var value=""; ???????var key=""; ???????var map = {}; ???????var str =""; ???????map["url"]=window.frames[0].location.toString(); ???????$(‘.searchParams‘).each(function () { ???????????value = $(this).val().toString(); ???????????key=$(this).attr("id"); ???????????map[key] = value; ???????????//主要:map转json字符串放入data ???????????str = JSON.stringify(map); ????????}); ???????$.ajax({ ???????????type:"POST", ???????????url:"fineReportController.do?getFineUrl", ???????????data:{ ???????????????strMap:str ???????????}, ????????????success:function(data){ ???????????????var d = $.parseJSON($.parseJSON(data).msg)[0]; ???????????????//姓名name是真实姓名_工号拼出来的,例如:张赛梅_160707302X ???????????????window.frames[0].location=encodeURI(encodeURI(d.fineUrl)); ???????????} ???????}); ???}</script> </head> <body><div style="height:50px;"> ???开始时间:<input id="dates" class="searchParams Wdate" type="text" value="${dates}" /> ???结束时间:<input id="datez" class="searchParams Wdate" type="text" ?value="${datez}"/> ???部门: ???<t:dictSelect id="dept" field="dept" type="list" dictTable="<%=dic%>" dictField="departname" dictText="departname" defaultVal="" hasLabel="false" ?title="部门" ></t:dictSelect> ????????<input id="department" class="searchParams" value="" type="hidden" /> ???姓名:<input id="name" class="searchParams" value="" type="text" /> ?????????????????<a class="l-btn" onclick="getFineReport()" href="#"> ???????<span class="l-btn-left"> ???????????<span class="l-btn-text icon-search l-btn-icon-left">查询</span> ???????</span> ???</a></div> ?<iframe id="reportFrame" width="100%" height="100%" src="${fineReport}" ></iframe> </body></html>

下面是后台代码:

package com.jeecg.xiaohaojiao.controller;import java.net.URLDecoder;import java.net.URLEncoder;import java.text.ParseException;import java.text.SimpleDateFormat;import java.util.Date;import java.util.HashMap;import java.util.Iterator;import java.util.Map;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import javax.validation.Validator;import org.apache.log4j.Logger;import org.jeecgframework.core.common.controller.BaseController;import org.jeecgframework.core.common.model.json.AjaxJson;import org.jeecgframework.web.system.service.SystemService;import org.jeecgframework.web.system.service.UserService;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.ResponseBody;import org.springframework.web.servlet.ModelAndView;import com.jeecg.xiaohaojiao.service.XhjUserDepartServiceI;import com.jeecg.xiaohaojiao.util.RoleUtil;import freemarker.template.SimpleDate;import net.sf.json.JSONObject;/** ???* @Title: Controller ??* @Description: 帆软报表页面跳转action * @author liuf * @date 2017-10-02 10:49:19 * @version V1.0 ???* */@Controller@RequestMapping("/fineReportController")public class FineReportController extends BaseController{ ???/** ????* Logger for this class ????*/ ???private static final Logger logger = Logger.getLogger(FineReportController.class); ???????//不同角色对应的部门ids ???private String departIds = ""; ???@Autowired ???private SystemService systemService; ???@Autowired ???private UserService userService; ???@Autowired ???private XhjUserDepartServiceI xhjUserDepartService; ???????/** ????* 无查询条件帆软报表页面跳转方法 ????* @param req ????* @return ????*/ ???@RequestMapping(params = "goFineReport") ???public ModelAndView goFineReport(HttpServletRequest req) { ???????String id = req.getParameter("id"); ???????String fineReportPath = "../WebReport/ReportServer?reportlet="+id+".cpt"; ???????req.setAttribute("fineReport", fineReportPath); ???????return new ModelAndView("xiaohaojiao/fineReport"); ???} ???????/** ????* 有查询条件需要控制页面权限帆软报表页面跳转方法 ????* @param req ????* @return ????* @throws ParseException ?????*/ ???@RequestMapping(params = "goFineReportForParams") ???public ModelAndView goFineReportForParams(HttpServletRequest req) throws ParseException { ???????SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); ???????SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM"); ???????????????Date date = new Date(); ???????String beginTime = sd.format(date); ???????String endTime = sdf.format(date); ???????req.setAttribute("dates", beginTime+"-01"); ???????req.setAttribute("datez", endTime); ???????????????try { ???????????departIds = RoleUtil.getDeptIds(req,systemService,userService,xhjUserDepartService); ???????} catch (Exception e) { ???????????e.printStackTrace(); ???????} ???????String id = req.getParameter("id"); ???????String fineReportPath = "../WebReport/ReportServer?reportlet="+id+".cpt"; ???????req.setAttribute("fineReport", fineReportPath); ???????req.setAttribute("departIds", departIds); ???????return new ModelAndView("xiaohaojiao/fineReportForParams"); ???} ???????/** ????* 页面点击查询的时候重新拼接的url,用于重新加载iframe ????* @param request ????* @param response ????* @return ????* @throws Exception ????*/ ???@RequestMapping(params = "getFineUrl") ???@ResponseBody ???public AjaxJson getFineUrl(HttpServletRequest request, HttpServletResponse response) throws Exception{ ???????String fineUrl = ""; ???????AjaxJson j = new AjaxJson(); ???????Map<String,Object> map = new HashMap<String ,Object>(); ???????String strMap = request.getParameter("strMap"); ???????JSONObject jb = JSONObject.fromObject(strMap); ???????Map filterMap = (Map)jb; ???????fineUrl = ((String) filterMap.get("url")).split("&")[0]; ???????Iterator<String> iter = filterMap.keySet().iterator(); ???????while (iter.hasNext()) { ??????????String key = iter.next(); ??????????String value = (String) filterMap.get(key); ??????????if (!"url".equals(key)) { ??????????????fineUrl = fineUrl + "&" + key + "=" + (value==null?"":value); ???????????} ??????????????????????} ???????map.put("fineUrl", fineUrl); ???????net.sf.json.JSONArray jsonArray = net.sf.json.JSONArray.fromObject(map); ???????j.setMsg(jsonArray.toString()); ???????return j; ???}}

帆软报表和jeecg的进一步整合--ajax给后台传递map类型的参数

原文地址:http://www.cnblogs.com/shuilangyizu/p/7788100.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved