- 软件安装
- 附加配置环境,附加 jdk1.7.0_79
我原来使用的为jdk1.8 再多配置一个1.7就可以了,不会发生冲突的.
- 把配置路径 修改到ireport.conf文件中如图:
- 报表制作
- 报表展示
- 报表含义
1.表头 和 标题
2.非数据参数
3.数据参数(Contorller中的reportList)可N 条逐条显示
4.合计类非数据信息 及表尾信息
注意:
- 位置分布:上顶线左顶线右靠边下靠边
- 图上3的位置只能放数据(不包括列名称等) 如放其他的会重复显示(3为整个Detail 1层)
- ${name} :的对应方法在java部分处理方法
-
报表ireport软件技术
1.新建页面
2.写sql 语句
3.导入sql
4.根据sql获取 ${} 的动态参数
5.画表格
6.具体操作见:https://blog.youkuaiyun.com/qq_18875541/article/details/69392215
-
报表属性例子如下:
- 静态
- 动态
- 函数(自定义求和函数)
右键添加自定义函数然后配置:
- 静态
-
处理
- i.点击锤子编译成 .jrxml 格式 锤子如图 :
- ii.把 ***.jrxml文件 复制到类如:E:\wdhis-emis\wdhis-emis-web\src\main\webapp\static\jaspers
- iii.修改Controller
//确定 .jasper文件位置 String filePath="/static/jaspers/minPFree.jasper";
- i.点击锤子编译成 .jrxml 格式 锤子如图 :
- java部分处理方法
- Web层布局如下
/**
* @Title: 统计报表<br>
* @Company: wondersgroup.com <br>
* @author
*/
@Controller
@RequestMapping("/reportForms/minPFree")
public class MinprotectFreeStatisticsController { //类名
@Autowired
AccOutPatInfoHandler accOutPatInfoHandler;
/**
* 跳转到报表
*/
@RequestMapping(value = "/goMinPFreeStatistics")
@ResponseBody
public ModelAndView goMinPFreeStatistics() { //用于跳转的方法
ModelAndView mav = new ModelAndView("repoortForms/minprotect-free-statistics");
return mav;
}
/**
* 报表,导出xls,pdf
*/
@RequestMapping(value ="/goMinPFreeStatisticsReport")
public void goMinPFreeStatisticsReport(HttpServletRequest request, HttpServletResponse response, MinPFreeStatisticsReportDto minPFreeStatisticsReportDto) throws IOException {
//由前端传回的minPFreeStatisticsReportDto 去获取需求信息
String docType = minPFreeStatisticsReportDto.getDocType();
Date nowTime = minPFreeStatisticsReportDto.getDbTime();
Date startTime = minPFreeStatisticsReportDto.getStartTime();
Date endTime = minPFreeStatisticsReportDto.getEndTime();
String discountTypeName = minPFreeStatisticsReportDto.getDiscountTypeName();
String branchName = minPFreeStatisticsReportDto.getBranchName();
//定义输出输入的格式(不需要自定义)
if(!StringUtils.isNotBlank(docType)){
docType = "html";
}
//获取session中的用户名
String userName= ContextHolder.getSessionUser().getName();
//调用获取数据的方法
List<Map<String,Object>> reportList=accOutPatInfoHandler.getAccOutPatInfo(minPFreeStatisticsReportDto);
// STEP 1 : 创建报表参数Map
Map parameters = new HashMap();
//系统年月日格式,如:2018-12-12 06:25:20
SimpleDateFormat sdf1 = new SimpleDateFormat(ParamConstants.DATE_FORMAT_YMDHMS);//调整时间类型
SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd");//调整时间类型
String startTimes = sdf2.format(startTime);//调整时间类型
String endTimes = sdf2.format(endTime);//调整时间类型
String nowTimes = sdf1.format(nowTime);//调整时间类型
parameters.put("statisDate", startTimes +" 至 "+ endTimes); //对应报表的 $P{statisDate}
parameters.put("pat",branchName); //对应报表的 $P{pat}
parameters.put("feeType",discountTypeName); //对应报表的 $P{feeType}
parameters.put("userDate", userName+"("+nowTimes+")"); //对应报表的 $P{userDate}
// STEP 2 : 指定数据源
JRDataSource datasource = new JRBeanCollectionDataSource(reportList);//把后台数据传入
// STEP 3 : 指定模板文件
ServletContext context = request.getSession().getServletContext();
String filePath="/static/jaspers/minPFree.jasper"; //确定 .jasper文件位置
File reportFile = new File(context.getRealPath(filePath));
String fileName = "null";
//* STEP 4 : 输出报表不同输出方式
try {
if ("html".equals(docType)) {
//使用html输出,表现为html页面
JasperUtil.showHtml( reportFile.getPath(),request, response, parameters, datasource);
} else if ("pdf".equals(docType)) {
//使用PDF输出,表现为出现PDF文件的下载对话框
JasperUtil.pdfExport(response,request,parameters,filePath,fileName,"pdf",null,datasource);
} else if ("excel".equals(docType)) {
//使用EXCEL输出,表现为出现EXCEL文件的下载对话框
JasperUtil.excleExport(response,request,parameters,filePath,fileName,"xls",null,datasource);
} else if ("word".equals(docType)) {
//使用Word输出,表现为出现EXCEL文件的下载对话框
JasperUtil.worldExport(response,request,parameters,filePath,fileName,"doc",null,datasource);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
- js部分处理方法
- service.js层
/**
* 服务定义
*
* @name {String} 服务方法名 必须 .
* @type {String} 请求方式,支持 'post' 和 'get',默认 'get' .
* @dataType {String} 同jQuery ajax 的对应参数,默认 'json' .
* @url {String} 请求路径,支持http(https)协议的绝对路径;否则,路径必须以'/'开头 .
* @contentType {String} 请求的内容类型(MineType) 默认 'application/json' .
*
*/
var serviceDefs = [
{name: 'goMinPFreeStatistics'}, //与Controller统计报表的RequestMapping对应
{name: 'goMinPFreeStatisticsReport', type: 'post', contentType: 'application/xml'},
];
return Service.inherit(serviceDefs, '/reportForms/minPFree');
});
//导出按钮 excel形式的操作
btnExcelClick: function () {
// 时间
var startTime = new moment(view.c('dtStartTime').getValue()).format("YYYY-MM-DD");
var endTime = new moment(view.c('dtEndTime').getValue()).format("YYYY-MM-DD");
// 制表
var dbTime = new moment(new Date()).format("YYYY-MM-DD HH:mm:ss");
$('#printIframe').attr('src', minPFreeStatisticsService.url(
'goMinPFreeStatisticsReport', {
'docType': 'excel',
'startTime': startTime,
'endTime': endTime,
}));
},
//检索按钮的js操作
btnSearchClick: function () {
// 时间
var startTime = new moment(view.c('dtStartTime').getValue()).format("YYYY-MM-DD");
var endTime = new moment(view.c('dtEndTime').getValue()).format("YYYY-MM-DD");
// 制表
var dbTime = new moment(new Date()).format("YYYY-MM-DD HH:mm:ss");
$.ajax({
url: minPFreeStatisticsService.url('goMinPFreeStatisticsReport'),
data: {
'startTime': startTime,
'endTime': endTime,
},
dataType: "html",//请求页面返回的数据类型
type: "GET",
contentType: "application/json",//注意请求页面的contentType 要于此处保持一致
success: function (data) {//这里的data是由请求页面返回的数据
$('#printIframe')[0].contentWindow.document.body.innerHTML = data;
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
}
});
}
};
上述代码为封装过的ajax的形式,请按不同封装调整
软件后期上传 需要的留言…
遇到的问题:
- ireport 的加减乘除(极为方便)
- “+”
- “-”
- “*”
- “/”
- 除数为零的问题
- 除数为零时会导致生成失败
- 解决方案
- " ( F v a r i a b l e 1 > 0 ) ? F{variable1}>0)? Fvariable1>0)?F{variable2}/$F{variable1}*100:0"
- 解释: 如果除数大于0 则进行除法 否则得数直接付为0
- 大家可以适当调整 (上面的代码 注意 : 没有引号哈)
- 可接收的对象
- 正确 : resultType=“java.util.Map”
- 注意 : 不是 resultMap 且一定是 Map 形式
- 如 : List<Map<String, Object>>