一区二区三区在线-一区二区三区亚洲视频-一区二区三区亚洲-一区二区三区午夜-一区二区三区四区在线视频-一区二区三区四区在线免费观看

服務(wù)器之家:專注于服務(wù)器技術(shù)及軟件下載分享
分類導(dǎo)航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術(shù)|正則表達(dá)式|C/C++|IOS|C#|Swift|Android|VB|R語言|JavaScript|易語言|vb.net|

服務(wù)器之家 - 編程語言 - Java教程 - 解析spring boot與ireport 整合問題

解析spring boot與ireport 整合問題

2022-03-01 00:38小方同學(xué)_ Java教程

本文通過實例代碼給大家介紹了spring boot 與 ireport 整合問題,關(guān)于pom文件依賴的問題通過實例代碼給大家介紹的非常詳細(xì),需要的朋友參考下吧

pom 文件依賴

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<dependency>
          <groupId>net.sf.jasperreports</groupId>
          <artifactId>jasperreports</artifactId>
          <version>6.10.0</version>
      </dependency>
      <dependency>
          <groupId>org.codehaus.groovy</groupId>
          <artifactId>groovy-all</artifactId>
          <version>2.4.11</version>
      </dependency>
      <!-- https://mvnrepository.com/artifact/cn.lesper/iTextAsian -->
      <!-- 解決中文字體顯示問題 -->
      <dependency>
          <groupId>cn.lesper</groupId>
          <artifactId>iTextAsian</artifactId>
          <version>3.0</version>
      </dependency>

controller

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
@GetMapping("/preview")
   public void print(HttpServletResponse response) throws Exception {
       List<Map<String, String>> data = getMaps();
       JRDataSource dataSource = new JRBeanCollectionDataSource(data);
       File file = ResourceUtils.getFile("classpath:jaspertemplate/abc.jrxml");
       response.setCharacterEncoding("utf-8");
       response.setContentType("application/pdf");
       response.setHeader("content-disposition", "attachment;filename=" + URLEncoder.encode("test", "UTF-8") + ".pdf");
 
       try (OutputStream outputStream = response.getOutputStream()) {
           //編譯jrxml
           JasperReport jasperReport = JasperCompileManager.compileReport(file.getPath());
           //渲染加載數(shù)據(jù)
           HashMap<String, Object> params = new HashMap<>();
           JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, params, dataSource);
           JasperExportManager.exportReportToPdfStream(jasperPrint, outputStream);
       } catch (IOException | JRException e) {
           e.printStackTrace();
       }
   }
 private List<Map<String, String>> getMaps() {
       List<Map<String, String>> data = new ArrayList<>();
       for (int i = 0; i < 10; i++) {
           Map<String, String> m = new HashMap<>(3);
           m.put("id", "id" + i);
           m.put("name", "測試" + i);
           m.put("price", "price" + i);
           m.put("volTitle", "測試" + i);
           data.add(m);
       }
       return data;
   }

abc.jrxml 文件

path:src/main/resources/jaspertemplate

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="會計案卷目錄" pageWidth="842" pageHeight="595" orientation="Landscape" columnWidth="782" leftMargin="30" rightMargin="30" topMargin="20" bottomMargin="20" uuid="69efba03-3736-408b-be3f-6295cabbbdfa">
    <property name="ireport.zoom" value="1.2078825000000022"/>
    <property name="ireport.x" value="48"/>
    <property name="ireport.y" value="0"/>
    <field name="volumnSeq" class="java.lang.String">
        <fieldDescription><![CDATA[volumnSeq]]></fieldDescription>
    </field>
    <field name="ajLb" class="java.lang.String">
        <fieldDescription><![CDATA[ajLb]]></fieldDescription>
    </field>
    <field name="volTitle" class="java.lang.String">
        <fieldDescription><![CDATA[volTitle]]></fieldDescription>
    </field>
    <field name="bgnDate" class="java.lang.String"/>
    <field name="fnshDate" class="java.lang.String"/>
    <field name="keepCode" class="java.lang.String">
        <fieldDescription><![CDATA[keepCode]]></fieldDescription>
    </field>
    <field name="docNmbr" class="java.lang.String">
        <fieldDescription><![CDATA[pageNmbr]]></fieldDescription>
    </field>
    <field name="remark" class="java.lang.String">
        <fieldDescription><![CDATA[remark]]></fieldDescription>
    </field>
    <field name="catalogNo" class="java.lang.String"/>
    <background>
        <band splitType="Stretch"/>
    </background>
    <title>
        <band height="75" splitType="Stretch">
            <staticText>
                <reportElement x="202" y="23" width="381" height="43" uuid="6dd7ca27-e8c4-4b52-964d-69045be9bf66"/>
                <textElement textAlignment="Center" verticalAlignment="Middle">
                    <font size="24" isBold="true" pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H" isPdfEmbedded="true"/>
                </textElement>
                <text><![CDATA[目 錄]]></text>
            </staticText>
        </band>
    </title>
    <columnHeader>
        <band height="35" splitType="Stretch">
            <staticText>
                <reportElement x="9" y="0" width="61" height="35" uuid="2f94f55b-9760-4417-95b0-99e91d5aac6f"/>
                <box>
                    <pen lineWidth="1.0" lineColor="#FF3333"/>
                    <topPen lineWidth="1.0" lineColor="#FF3333"/>
                    <leftPen lineWidth="1.0" lineColor="#FF3333"/>
                    <bottomPen lineWidth="1.0" lineColor="#FF3333"/>
                    <rightPen lineWidth="0.0" lineColor="#FF3333"/>
                </box>
                <textElement textAlignment="Center" verticalAlignment="Middle">
                    <font size="12" pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H" isPdfEmbedded="true"/>
                </textElement>
                <text><![CDATA[順序號 ]]></text>
            </staticText>
            <staticText>
                <reportElement x="70" y="0" width="68" height="35" uuid="bef549c0-dc52-41f1-b291-f515a6337a7c"/>
                <box>
                    <pen lineWidth="1.0" lineColor="#FF3333"/>
                    <topPen lineWidth="1.0" lineColor="#FF3333"/>
                    <leftPen lineWidth="1.0" lineColor="#FF3333"/>
                    <bottomPen lineWidth="1.0" lineColor="#FF3333"/>
                    <rightPen lineWidth="0.0" lineColor="#FF3333"/>
                </box>
                <textElement textAlignment="Center" verticalAlignment="Middle">
                    <font size="12" pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H" isPdfEmbedded="true"/>
                </textElement>
                <text><![CDATA[類別]]></text>
            </staticText>
            <staticText>
                <reportElement x="138" y="0" width="360" height="35" uuid="98ac28b1-101a-43ae-a838-1fbe3edaae7c"/>
                <box>
                    <pen lineWidth="1.0" lineStyle="Solid" lineColor="#FF3333"/>
                    <topPen lineWidth="1.0" lineStyle="Solid" lineColor="#FF3333"/>
                    <leftPen lineWidth="1.0"/>
                    <bottomPen lineWidth="1.0" lineStyle="Solid" lineColor="#FF3333"/>
                    <rightPen lineWidth="0.0"/>
                </box>
                <textElement textAlignment="Center" verticalAlignment="Middle">
                    <font size="12" pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H" isPdfEmbedded="true"/>
                </textElement>
                <text><![CDATA[標(biāo)題]]></text>
            </staticText>
            <staticText>
                <reportElement x="498" y="0" width="100" height="35" uuid="b72ae79e-9c50-4e0f-b7fe-a0baeabc75d6"/>
                <box>
                    <pen lineWidth="1.0" lineColor="#000000"/>
                    <topPen lineStyle="Solid" lineColor="#FF3333"/>
                    <leftPen lineStyle="Solid" lineColor="#FF3333"/>
                    <bottomPen lineStyle="Solid" lineColor="#FF3333"/>
                    <rightPen lineWidth="0.0" lineStyle="Solid" lineColor="#FF3333"/>
                </box>
                <textElement textAlignment="Center" verticalAlignment="Middle">
                    <font size="12" pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H" isPdfEmbedded="true"/>
                </textElement>
                <text><![CDATA[起止時間]]></text>
            </staticText>
            <staticText>
                <reportElement x="598" y="0" width="54" height="35" uuid="ef0be213-7372-4f63-85d0-11b0c68db41e"/>
                <box>
                    <topPen lineWidth="1.0" lineColor="#FF3333"/>
                    <leftPen lineWidth="1.0" lineColor="#FF3333"/>
                    <bottomPen lineWidth="1.0" lineColor="#FF3333"/>
                    <rightPen lineWidth="1.0" lineStyle="Solid" lineColor="#FF3333"/>
                </box>
                <textElement textAlignment="Center" verticalAlignment="Middle">
                    <font size="12" pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H" isPdfEmbedded="true"/>
                </textElement>
                <text><![CDATA[保管期限]]></text>
            </staticText>
            <staticText>
                <reportElement x="653" y="0" width="50" height="35" uuid="c2940de1-cdba-4a39-b2d1-537c3d245c2a"/>
                <box>
                    <topPen lineWidth="1.0" lineColor="#FF3333"/>
                    <bottomPen lineWidth="1.0" lineColor="#FF3333"/>
                </box>
                <textElement textAlignment="Center" verticalAlignment="Middle">
                    <font size="12" pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H" isPdfEmbedded="true"/>
                </textElement>
                <text><![CDATA[張數(shù)]]></text>
            </staticText>
            <staticText>
                <reportElement x="703" y="0" width="63" height="35" uuid="42adecdf-1d7c-4485-b389-88a99a16da24"/>
                <box>
                    <topPen lineWidth="1.0" lineColor="#FF3333"/>
                    <leftPen lineWidth="1.0" lineColor="#FF3333"/>
                    <bottomPen lineWidth="1.0" lineColor="#FF3333"/>
                    <rightPen lineWidth="1.0" lineColor="#FF3333"/>
                </box>
                <textElement textAlignment="Center" verticalAlignment="Middle">
                    <font size="12" pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H" isPdfEmbedded="true"/>
                </textElement>
                <text><![CDATA[備   注]]></text>
            </staticText>
        </band>
    </columnHeader>
    <detail>
        <band height="40" splitType="Stretch">
            <textField isBlankWhenNull="true">
                <reportElement x="9" y="0" width="61" height="40" uuid="2daafeea-13c0-4ec3-919d-0409c5723171"/>
                <box>
                    <pen lineWidth="1.0" lineColor="#FF3333"/>
                    <topPen lineWidth="0.0"/>
                    <leftPen lineWidth="1.0" lineColor="#FF3333"/>
                    <bottomPen lineWidth="1.0" lineColor="#FF3333"/>
                    <rightPen lineWidth="0.0"/>
                </box>
                <textElement textAlignment="Center" verticalAlignment="Middle">
                    <font size="12" pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H" isPdfEmbedded="true"/>
                </textElement>
                <textFieldExpression><![CDATA[$F{volumnSeq}]]></textFieldExpression>
            </textField>
            <textField isBlankWhenNull="true">
                <reportElement x="70" y="0" width="68" height="40" uuid="0ff74e34-785d-482f-a67a-72a66635bcc2"/>
                <box>
                    <pen lineWidth="1.0"/>
                    <topPen lineWidth="0.0" lineColor="#FF3333"/>
                    <leftPen lineWidth="1.0" lineColor="#FF3333"/>
                    <bottomPen lineWidth="1.0" lineColor="#FF3333"/>
                    <rightPen lineWidth="0.0" lineColor="#FF3333"/>
                </box>
                <textElement textAlignment="Center" verticalAlignment="Middle">
                    <font size="12" pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H" isPdfEmbedded="true"/>
                </textElement>
                <textFieldExpression><![CDATA[$F{ajLb}]]></textFieldExpression>
            </textField>
            <textField isBlankWhenNull="true">
                <reportElement x="138" y="0" width="360" height="40" uuid="88d06173-5259-4897-895d-a39434e079f2"/>
                <box>
                    <topPen lineWidth="1.0" lineColor="#FF3333"/>
                    <leftPen lineWidth="1.0" lineColor="#FF3333"/>
                    <bottomPen lineWidth="1.0" lineColor="#FF3333"/>
                    <rightPen lineWidth="1.0" lineColor="#FF3333"/>
                </box>
                <textElement textAlignment="Justified" verticalAlignment="Middle">
                    <font size="12" pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H" isPdfEmbedded="true"/>
                </textElement>
                <textFieldExpression><![CDATA[$F{volTitle}]]></textFieldExpression>
            </textField>
            <textField isBlankWhenNull="true">
                <reportElement x="525" y="0" width="70" height="20" uuid="45d93afa-bd67-4f27-a3e1-c301e84ed0ea"/>
                <box>
                    <bottomPen lineWidth="0.0"/>
                </box>
                <textElement textAlignment="Center" verticalAlignment="Middle">
                    <font size="12" pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H" isPdfEmbedded="true"/>
                </textElement>
                <textFieldExpression><![CDATA[$F{bgnDate}]]></textFieldExpression>
            </textField>
            <textField isBlankWhenNull="true">
                <reportElement x="652" y="0" width="50" height="40" uuid="3e13e790-2e18-4154-8331-ee2ab0b8f8ad"/>
                <box>
                    <leftPen lineWidth="1.0" lineColor="#FF3333"/>
                    <bottomPen lineWidth="1.0" lineColor="#FF3333"/>
                </box>
                <textElement textAlignment="Center" verticalAlignment="Middle">
                    <font size="12" pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H" isPdfEmbedded="true"/>
                </textElement>
                <textFieldExpression><![CDATA[$F{docNmbr}]]></textFieldExpression>
            </textField>
            <textField isBlankWhenNull="true">
                <reportElement x="525" y="20" width="73" height="20" uuid="b07739c0-f452-4a53-b104-e281f40c6133"/>
                <box>
                    <pen lineColor="#FF3333"/>
                    <topPen lineColor="#FF3333"/>
                    <leftPen lineColor="#FF3333"/>
                    <bottomPen lineWidth="1.0" lineColor="#FF3333"/>
                    <rightPen lineColor="#FF3333"/>
                </box>
                <textElement textAlignment="Center" verticalAlignment="Middle">
                    <font size="12" pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H" isPdfEmbedded="true"/>
                </textElement>
                <textFieldExpression><![CDATA[$F{fnshDate}]]></textFieldExpression>
            </textField>
            <staticText>
                <reportElement x="498" y="0" width="30" height="20" uuid="d81412e7-1078-444a-90f4-e038ac6f30af"/>
                <box>
                    <leftPen lineWidth="1.0" lineColor="#FF3333"/>
                    <bottomPen lineWidth="0.0"/>
                </box>
                <textElement textAlignment="Center" verticalAlignment="Middle">
                    <font size="12" pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H" isPdfEmbedded="true"/>
                </textElement>
                <text><![CDATA[自]]></text>
            </staticText>
            <staticText>
                <reportElement x="498" y="20" width="30" height="20" uuid="474ba566-24b3-4681-baf7-21d9647771d9"/>
                <box>
                    <leftPen lineWidth="1.0" lineColor="#FF3333"/>
                    <bottomPen lineWidth="1.0" lineColor="#FF3333"/>
                </box>
                <textElement textAlignment="Center" verticalAlignment="Middle">
                    <font size="12" pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H" isPdfEmbedded="true"/>
                </textElement>
                <text><![CDATA[至]]></text>
            </staticText>
            <textField isBlankWhenNull="true">
                <reportElement x="703" y="0" width="63" height="40" uuid="0cab3c98-0f59-42c4-920b-118f942bcbb9"/>
                <box>
                    <leftPen lineWidth="1.0" lineColor="#FF3333"/>
                    <bottomPen lineWidth="1.0" lineStyle="Solid" lineColor="#FF3333"/>
                    <rightPen lineWidth="1.0" lineStyle="Solid" lineColor="#FF3333"/>
                </box>
                <textElement textAlignment="Center" verticalAlignment="Middle">
                    <font size="12" pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H" isPdfEmbedded="true"/>
                </textElement>
                <textFieldExpression><![CDATA[$F{remark}]]></textFieldExpression>
            </textField>
            <textField isBlankWhenNull="true">
                <reportElement x="598" y="0" width="54" height="40" uuid="79eb3d06-f603-45b1-aa89-f8713daf6473"/>
                <box>
                    <leftPen lineWidth="1.0" lineColor="#FF3333"/>
                    <bottomPen lineWidth="1.0" lineColor="#FF3333"/>
                </box>
                <textElement textAlignment="Center" verticalAlignment="Middle">
                    <font size="12" pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H" isPdfEmbedded="true"/>
                </textElement>
                <textFieldExpression><![CDATA[$F{keepCode}]]></textFieldExpression>
            </textField>
        </band>
    </detail>
    <pageFooter>
        <band height="45" splitType="Stretch"/>
    </pageFooter>
</jasperReport>

其他

本文不涉及有關(guān)ireport報表如何設(shè)計問題,有需要請自行查詢 Y(_)Y

到此這篇關(guān)于spring boot 與 ireport 整合的文章就介紹到這了,更多相關(guān)spring boot ireport 整合內(nèi)容請搜索服務(wù)器之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持服務(wù)器之家!

原文鏈接:https://blog.csdn.net/junoohoome/article/details/115913261

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 国产永久一区二区三区 | 四虎网站最新网址 | 干操视频 | 99精品热线在线观看免费视频 | 视频一区在线观看 | 日本福利片国产午夜久久 | 国产成人无精品久久久 | 天堂在线免费观看 | 高h折磨调教古代 | 高清女主播一区二区三区 | 无套插入 | 亚洲一欧洲中文字幕在线 | 高清一区高清二区视频 | 日韩无砖2021特黄 | 四虎1515hhc0m| 成人男女网免费 | 99久久综合给久久精品 | 波多野结衣无码 | 国产香蕉一区二区精品视频 | 日本大乳护士的引诱图片 | 日本大乳护士的引诱图片 | 黄 色 大 片 网站 | 乌克兰成人性色生活片 | 日本漫画工囗全彩番在线 | 美女黄板视频 | 日日操天天爽 | 欧美日韩亚洲国内综合网俺 | 亚洲精品精品一区 | 男人狂躁女人下面狂叫图片 | 日本在线视 | 99热这里只有精品国产免费 | 二次元美女互摸隐私互扒 | 欧美日本一区视频免费 | 国产伦精品一区二区 | 俄罗斯一级大片 | 18hdxxxx日本护士 | 精品无人区乱码1区2区3区免费 | 841995论坛网站2022年 | 五月色婷婷网在线观看 | 亚洲欧美另类专区 | 日韩精品在线一区二区 |