JasperReport (三) 主子报表的实现

2023年 10月 8日 150.6k 0

一、数据源创建

1.1 学生表

CREATE TABLE Student(
SID NUMBER,
NAME VARCHAR(20)
);

1.2 教师表

CREATE  TABLE Teacher(
TID NUMBER,
NAME VARCHAR(20)
);

1.3 课程信息表

CREATE  TABLE CourseList(
CID NUMBER,
TID NUMBER,
NAME VARCHAR(20)
);

1.4 学科成绩表

CREATE  TABLE CourseScore(
SID NUMBER,
CID NUMBER,
SCORE NUMBER
);

1.5 数据插入

-- Student 表
INSERT INTO STUDENT ("SID", "NAME") VALUES ('1', '张三');
INSERT INTO STUDENT ("SID", "NAME") VALUES ('2', '李四');
-- Teacher 表
INSERT INTO TEACHER ("TID", "NAME") VALUES ('1', '老王');
INSERT INTO TEACHER ("TID", "NAME") VALUES ('2', '老李');
INSERT INTO TEACHER ("TID", "NAME") VALUES ('3', '老张');
-- CourseList 表
INSERT INTO CourseList ("CID", "TID", "NAME") VALUES ('1', '1', '语文');
INSERT INTO CourseList ("CID", "TID", "NAME") VALUES ('2', '2', '英语');
INSERT INTO CourseList ("CID", "TID", "NAME") VALUES ('3', '3', '数学');
-- CourseScore 表
INSERT INTO CourseScore ("SID", "CID", "SCORE") VALUES ('1', '1', '50');
INSERT INTO CourseScore ("SID", "CID", "SCORE") VALUES ('1', '2', '60');
INSERT INTO CourseScore ("SID", "CID", "SCORE") VALUES ('1', '3', '80');
INSERT INTO CourseScore ("SID", "CID", "SCORE") VALUES ('2', '1', '90');
INSERT INTO CourseScore ("SID", "CID", "SCORE") VALUES ('2', '2', '88');
INSERT INTO CourseScore ("SID", "CID", "SCORE") VALUES ('2', '3', '86');

1.6 语句整合

CREATE TABLE Student(
SID NUMBER,
NAME VARCHAR(20)
);

CREATE  TABLE Teacher(
TID NUMBER,
NAME VARCHAR(20)
);

CREATE  TABLE CourseList(
CID NUMBER,
TID NUMBER,
NAME VARCHAR(20)
);

CREATE  TABLE CourseScore(
SID NUMBER,
CID NUMBER,
SCORE NUMBER
);

-- Student 表
INSERT INTO STUDENT ("SID", "NAME") VALUES ('1', '张三');
INSERT INTO STUDENT ("SID", "NAME") VALUES ('2', '李四');
-- Teacher 表
INSERT INTO TEACHER ("TID", "NAME") VALUES ('1', '老王');
INSERT INTO TEACHER ("TID", "NAME") VALUES ('2', '老李');
INSERT INTO TEACHER ("TID", "NAME") VALUES ('3', '老张');
-- CourseList 表
INSERT INTO CourseList ("CID", "TID", "NAME") VALUES ('1', '1', '语文');
INSERT INTO CourseList ("CID", "TID", "NAME") VALUES ('2', '2', '英语');
INSERT INTO CourseList ("CID", "TID", "NAME") VALUES ('3', '3', '数学');
-- CourseScore 表
INSERT INTO CourseScore ("SID", "CID", "SCORE") VALUES ('1', '1', '50');
INSERT INTO CourseScore ("SID", "CID", "SCORE") VALUES ('1', '2', '60');
INSERT INTO CourseScore ("SID", "CID", "SCORE") VALUES ('1', '3', '80');
INSERT INTO CourseScore ("SID", "CID", "SCORE") VALUES ('2', '1', '90');
INSERT INTO CourseScore ("SID", "CID", "SCORE") VALUES ('2', '2', '88');
INSERT INTO CourseScore ("SID", "CID", "SCORE") VALUES ('2', '3', '86');

commit;

二、 创建主报表文件

2.1 获取字段列表

select SID as "学号",Name as "姓名" from student

image.png

2.2 修改执行语句

2.2.1 创建变量

image.png

2.2.3 修改执行语句

select SID as "学号",Name as "姓名"
from student
where name like '%' || $P{姓名} || '%'

image.png

2.3 页面布局

image.png

三、创建子报表

3.1 获取数据字段

SELECT  cl.Name "课程名",t.Name "任课老师名", cs.SCORE "成绩" 
FROM  CourseScore  cs LEFT JOIN  Student s ON s.SID = cs.SID LEFT JOIN CourseList cl ON cs.CID = cl.CID 
LEFT JOIN Teacher t ON t.TID = cl.TID

image.png

3.2 修改执行语句

3.2.1 创建变量

image.png

3.2.2 修改执行语句

SELECT cl.Name "课程名",t.Name "任课老师名", cs.SCORE "成绩"
FROM CourseScore cs LEFT JOIN Student s ON s.SID = cs.SID LEFT JOIN CourseList cl ON cs.CID = cl.CID
LEFT JOIN Teacher t ON t.TID = cl.TID
WHERE s.SID = $P{学号}

image.png

3.3 页面布局

调整大小、边距

image.png

除了detail1,删除其他控件

image.png

四、在主报表文件导入子报表

4.1 导入子报表

image.png

image.png

4.2 配置Jdbc

image.png

4.3 配置参数

image.png

4.4 调整报表位置

image.png

4.5 测试

image.png

image.png

相关文章

JavaScript2024新功能:Object.groupBy、正则表达式v标志
PHP trim 函数对多字节字符的使用和限制
新函数 json_validate() 、randomizer 类扩展…20 个PHP 8.3 新特性全面解析
使用HTMX为WordPress增效:如何在不使用复杂框架的情况下增强平台功能
为React 19做准备:WordPress 6.6用户指南
如何删除WordPress中的所有评论

发布评论