request.getSession().getServletContext().getRealPath() // 虚拟目录映射为实际目录

本文介绍了一个Java Web中常用的方法:通过使用request.getSession().getServletContext().getRealPath()将虚拟目录映射为服务器上的实际文件路径。这对于处理文件上传下载等功能非常实用。

request.getSession().getServletContext().getRealPath()  // 虚拟目录映射为实际目录

public List<GrpOrgInfoSettingDomain> getCombinedRatioReport(FileDownForm filterMask); @PostMapping(value = "/commons/download/downReport") public ModelAndView resultDownload(HttpServletRequest request, HttpServletResponse response, FileDownForm filterMask) throws IOException { ModelAndView modelAndView = null; String path = request.getSession().getServletContext().getRealPath("") + Constant.PATH_FIX; log.info("path:{}" +path); StringBuilder fileName = new StringBuilder(); // 根据前端传入报表代码,获取数据库报表配置信息 String repSubName = "01";// 报表子类型默认为01 if (Constant.isEmpty(filterMask.getRepSubName())) { filterMask.setRepSubName(repSubName); } if(!Constant.isEmpty(filterMask.getChannel())){ List<TcompanyOrganDomain> organList =tcompanyOrganService.getOrganCodeByOrganIdLsprod(filterMask.getOrganId(),filterMask.getChannel()); filterMask.setOrganCode(organList.get(0).getOrganCode()); }else{ if (!Constant.isEmpty(filterMask.getOrganId())) { TcompanyOrganDomain company=new TcompanyOrganDomain(); company.setOrganId(Long.parseLong(filterMask.getOrganId())); List<TcompanyOrganDomain> organList = tcompanyOrganService.selectList(company); filterMask.setOrganCode(organList.get(0).getOrganCode()); } } TgrpReportConfigDomain reportConfig = tgrpReportConfigService.selectReportConfig(filterMask); if (reportConfig != null) { String downloadType = reportConfig.getDownloadType(); String sqlId = reportConfig.getSqlId(); String reportDesp = reportConfig.getReportDesp(); String viewName = reportConfig.getViewName(); // 前端传入YM不为空,将YM组装到报表名称中 if (StringUtils.isNotEmpty(filterMask.getYm())) { fileName.append(filterMask.getYm()); } fileName.append(reportDesp).append("_"); fileName.append(DateUtil.getCurrentDate(Constant.YYYYMMDDHHMMSS)); fileName.append(".xls"); if (XML.equals(downloadType)) { List list = tgrpReportConfigService.selectReportList(sqlId, filterMask); // 设置报表文件名称 response.addHeader(Constant.CONTENT_DISPOSITION, Constant.ATTACHMENT_FILE + URLEncoder.encode(fileName.toString(), Constant.UTF_8)); Map<String, Object> map = new HashMap<>(); map.put("list", list); map.put("viewName", viewName); return new ModelAndView("sheetExcelView", map); } } return modelAndView; } <!--报表下载--> <select id="getCombinedRatioReport" parameterType="com.foresealife.newglschannel.grp.domain.FileDownForm" resultMap="CombinedRatioResultMap"> <include refid="CombinedRatioQuery" /> </select> <!-- 查询sql结果与java model映射--> <resultMap id="CombinedRatioResultMap" type="com.foresealife.newglschannel.grp.domain.GrpOrgInfoSettingDomain"> <result property="organCode" column="ORGAN_CODE"/> <result property="organName" column="ORGAN_NAME"/> <result property="ym" column="YM"/> <result property="setValue" column="SET_VALUE"/> </resultMap> <!-- 公用查询sql--> <sql id="CombinedRatioQuery"> <![CDATA[ select ois.organ_code, to_char(ois.start_date, 'yyyy') ym, ois.set_value,tco.abbr_name organ_name from T_GRP_ORG_INFO_SETTING ois,t_company_organ tco where ois.set_type = '1' and ois.organ_code=tco.organ_code ]]> <if test= "organId != null and organId != ''"> and tco.organ_id in (select t.organ_id from t_company_organ t where t.status = 1 start with t.organ_id = #{organId} connect by PRIOR t.organ_id = t.parent_id) </if> <if test= "ym != null and ym != ''"> and ois.start_date = to_date(#{ym} || '0101', 'yyyymmdd') </if> </sql>报错c.f.n.core.support.AppContext - 根据名称:GrpOrgInfoSettingDao获取bean为空 org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'GrpOrgInfoSettingDao' available c.f.n.c.support.GlobalServiceSupport - 查询所有对象集合异常{}: java.lang.NullPointerException: null
最新发布
11-07
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值