SpringBoot使用Jsp预览水晶报表:项目搭建并预览报表
程序员文章站
2022-03-16 15:00:39
一、开发环境IntelliJ IDEA 2019.1.2 x64jdk8SpringBoot版本:2.3.4.RELEASE水晶报表依赖版本:CR4ERL26_0-80004572二、搭建SpringBoot并访问Jsp1创建SpringBooot项目pom.xml
目录
3拷贝crystalreportviewers和template目录中的CRConfig.xml
项目已上传git:https://gitee.com/373616511/spring-boot-crystal-reports-jsp-demo.git
一、开发环境
IntelliJ IDEA 2019.1.2 x64
jdk8
SpringBoot版本:2.3.4.RELEASE
水晶报表依赖版本:CR4ERL26_0-80004572
二、搭建SpringBoot并访问Jsp
1创建SpringBooot项目
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.4.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.asyf</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>demo</name>
<description>Demo project for CrystalReports</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<!-- spring boot 内置tomcat jsp支持 -->
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
</dependency>
<!--jsp页面使用jstl标签-->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
<!--tomcat-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<!-- <scope>provided</scope>-->
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
2创建webapp文件夹
D:\workspace\idea\SpringBootCrystalReportsJspDemo\src\main\webapp\WEB-INF\web.xml
D:\workspace\idea\SpringBootCrystalReportsJspDemo\src\main\webapp
3创建jsp文件
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<h1>首页</h1>
</body>
</html>
4添加controller
@Controller
public class DemoController {
@RequestMapping("/index")
public String hello(Model m) {
m.addAttribute("now", DateFormat.getDateTimeInstance().format(new Date()));
//视图重定向index.jsp
return "index";
}
}
5修改配置文件application.properties
spring.mvc.view.prefix=/
spring.mvc.view.suffix=.jsp
6确认项目结构
如果不把webapp设置ResourceFolders中,找不到jsp文件。
7项目目录图示以及测试
三、SpringBoot项目中加入水晶报表组件
1下载水晶报表CR4ERL26_0-80004572
链接地址
https://origin.softwaredownloads.sap.com/public/site/index.html
2添加jar包到WEB-INF/lib目录并引入到项目
3拷贝crystalreportviewers和template目录中的CRConfig.xml
- crystalreportviewers需要该名称crystalreportviewers120
- 移动crystal-tags-reportviewer.tld到WEB-INF目录
- CRConfig.xml放在webapp目录下
位置如下图
四、测试
1创建空报表测试
test.rpt 的创建方法自行百度或者参考博客https://blog.csdn.net/cs373616511/article/details/109269674
本文地址:https://blog.csdn.net/cs373616511/article/details/109953182