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 测试

相关推荐
海绵波波1074 小时前
flask后端开发(10):问答平台项目结构搭建
后端·python·flask
网络风云5 小时前
【魅力golang】之-反射
开发语言·后端·golang
Q_19284999065 小时前
基于Spring Boot的电影售票系统
java·spring boot·后端
运维&陈同学7 小时前
【Kibana01】企业级日志分析系统ELK之Kibana的安装与介绍
运维·后端·elk·elasticsearch·云原生·自动化·kibana·日志收集
Javatutouhouduan9 小时前
如何系统全面地自学Java语言?
java·后端·程序员·编程·架构师·自学·java八股文
后端转全栈_小伵9 小时前
MySQL外键类型与应用场景总结:优缺点一目了然
数据库·后端·sql·mysql·学习方法
编码浪子10 小时前
Springboot高并发乐观锁
后端·restful
uccs10 小时前
go 第三方库源码解读---go-errorlint
后端·go
Mr.朱鹏11 小时前
操作002:HelloWorld
java·后端·spring·rabbitmq·maven·intellij-idea·java-rabbitmq
编程洪同学12 小时前
Spring Boot 中实现自定义注解记录接口日志功能
android·java·spring boot·后端