JasperReport (三) 主子报表的实现

一、数据源创建

1.1 学生表

sql 复制代码
CREATE TABLE Student(
SID NUMBER,
NAME VARCHAR(20)
);

1.2 教师表

sql 复制代码
CREATE  TABLE Teacher(
TID NUMBER,
NAME VARCHAR(20)
);

1.3 课程信息表

sql 复制代码
CREATE  TABLE CourseList(
CID NUMBER,
TID NUMBER,
NAME VARCHAR(20)
);

1.4 学科成绩表

scss 复制代码
CREATE  TABLE CourseScore(
SID NUMBER,
CID NUMBER,
SCORE NUMBER
);

1.5 数据插入

sql 复制代码
-- 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 语句整合

sql 复制代码
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

2.2 修改执行语句

2.2.1 创建变量

2.2.3 修改执行语句

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

2.3 页面布局

三、创建子报表

3.1 获取数据字段

sql 复制代码
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

3.2 修改执行语句

3.2.1 创建变量

3.2.2 修改执行语句

sql 复制代码
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{学号}

3.3 页面布局

调整大小、边距

除了detail1,删除其他控件

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

4.1 导入子报表

4.2 配置Jdbc

4.3 配置参数

4.4 调整报表位置

4.5 测试

相关推荐
河西石头1 分钟前
一步一步从asp.net core mvc中访问asp.net core WebApi
后端·asp.net·mvc·.net core访问api·httpclient的使用
2401_8574396912 分钟前
SpringBoot框架在资产管理中的应用
java·spring boot·后端
怀旧66614 分钟前
spring boot 项目配置https服务
java·spring boot·后端·学习·个人开发·1024程序员节
阿华的代码王国34 分钟前
【SpringMVC】——Cookie和Session机制
java·后端·spring·cookie·session·会话
德育处主任Pro1 小时前
『Django』APIView基于类的用法
后端·python·django
哎呦没3 小时前
SpringBoot框架下的资产管理自动化
java·spring boot·后端
2401_857600953 小时前
SpringBoot框架的企业资产管理自动化
spring boot·后端·自动化
NiNg_1_2348 小时前
SpringBoot整合SpringSecurity实现密码加密解密、登录认证退出功能
java·spring boot·后端
Chrikk9 小时前
Go-性能调优实战案例
开发语言·后端·golang
幼儿园老大*9 小时前
Go的环境搭建以及GoLand安装教程
开发语言·经验分享·后端·golang·go