最近在写一个thymeleaf模板引擎的功能读取模板填充数据生成html文件并导出zip包 本地window是环境下一切都是没有问题的但是在linux环境下导出的 html都是乱码
我用的是SpringTemplateEngine.process(模板名称,内容,FileWriter )这个方法
FileWriter writer = new FileWriter(filePath,true);
一开始(输出路径)用的是 FileWriter 后来发现 Java FileWriter 默认是用(ISO-8859-1 or US-ASCII)西方编码的,而FileWriter类没有setEncoding的方法。希望通过设置编码方式的计划破灭了
后来将FileWriter 换成
BufferedWriter writer = new BufferedWriter (new OutputStreamWriter (new FileOutputStream (filePath,true),"UTF-8"));
就可以了
最后提醒一下 fileWriter.close();一定不要忘了写了。
下面加上我的模板和controller方法
html
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8"></meta>
<title>动态表格</title>
</head>
<body>
<div class="content">
<div id="page1" class="page">
<h1>跨机构进件api接口对接文档</h1>
<div class="page_footer">
<h2>杭州xx信息科技有限公司</h2>
<p th:text="${formatTime}">20XX年XX月XX日</p>
</div>
</div>
<div id="page2" class="page">
<div class="page_catalogue">
<h1>目录</h1>
<div class="title_href">
<a href="#page3"><h2 class="first_title">一、文档简介<span>...........................................................................</span>
</h2></a>
</div>
<div class="title_href">
<a href="#page3-1"><h2>二、对接流程<span>...........................................................................</span>
</h2></a>
<div class="second_title">
<a href="#page3-2"><p>1、参数获取<span>......................................................................</span>
</p></a>
<a href="#page4"><p>2、对接流程 <span>.....................................................................</span>
</p></a>
</div>
</div>
<div class="title_href">
<a href="#page5"><h2>三、对接准备 <span>..........................................................................</span>
</h2></a>
<div class="second_title">
<a href="#page5-1"><p>1、通讯方式<span>......................................................................</span>
</p></a>
<a href="#page6"><p>2、加密方式 <span>.....................................................................</span>
</p></a>
</div>
</div>
<div class="title_href">
<a href="#page7"><h2 class="first_title">四、名词解释 <span>..........................................................................</span>
</h2></a>
</div>
<div class="title_href">
<a href="#page8"><h2>五、对接接口<span>...........................................................................</span>
</h2></a>
<div class="second_title" >
<a href="#page8-1"><p>1、新建订单<span>......................................................................</span></p> </a>
</div>
<div class="second_title" >
<a href="#page8-2"><p>2、查询订单状态<span>.................................................................</span></p> </a>
</div>
<div class="second_title" >
<a href="#page8-3"><p>3、流程内取消订单<span>..............................................................</span></p> </a>
</div>
<div class="second_title" >
<a href="#page8-4"><p>4、流程外取消订单<span>..............................................................</span></p> </a>
</div>
<div class="second_title" th:each="userinfo:${apiName}">
<a th:href="${userinfo.page}"><p th:text="${userinfo.name}" ></p> </a>
</div>
</div>
<div class="title_href">
<a href="#page9"><h2 class="first_title">六、错误码<span>.............................................................................</span>
</h2></a>
</div>
<div class="title_href">
<a href="#page10"><h2 class="first_title">七、常见问题 <span>..........................................................................</span>
</h2></a>
</div>
</div>
</div>
<div id="page3" class="page">
<div class="wrap">
<h1>一、文档简介</h1>
<p>本文档针对机构对接xxx跨机构进件进行说明。
文档包括了对接流程、对接准备、名词解释、对接接口、异常状态、常见文档等六块内容进行详细说明,便于相关对接人员在对接过程中给出标准化的解释。所涉及的对接事宜相关人员皆可查阅该文档。</p>
</div>
<div class="wrap" id="page3-1">
<h1>二、对接流程</h1>
<h2 id="page3-2">1、参数获取</h2>
<p>对接前,需要配置一系列参数,参数含盖合作机构编码、渠道编码、业务编码、准入编码、密钥、消息/通知回调地址及IP白名单地址组成。
参数不全或错误时系统无法正常走单,同时配置参数分为从上方机构获取和自身机构提供两方面进行,具体获取方式及内容详见下方详细说明:</p>
</div>
<div class="wrap">
<h3>1.1、需从上方机构获取的参数</h3>
<ul>
<li>(1)合作机构编码</li>
<li>(2)渠道编码</li>
<li>(3)业务编码</li>
<li>(4)准入编码</li>
<li>(5)密钥</li>
</ul>
</div>
<div class="wrap">
<h3>1.2、自身机构需提供的参数</h3>
<ul>
<li>(1)消息/通知回调地址:需提供<span class="red">测试及生产环境</span>两个地址。</li>
<li>(2)IP白名单地址:需提供<span class="red">测试及生产环境</span>两个地址。</li>
</ul>
</div>
<div class="wrap">
<h3>1.3、参数获取方式</h3>
<p>上方机构参数获取需提供对应的邮箱,上方机构或系统技术支持方会通过邮件形式发送对应的参数信息。
自身机构参数发送至上方机构或系统技术支持方的邮箱内(上方机构邮箱:
<span class="underline"> </span>
系统支持方邮箱:<span class="underline"> jinyunduijie@qizhixinxi.com </span>)。
</p>
</div>
</div>
<div id="page4" class="page">
<div class="wrap">
<h2>2、对接流程</h2>
<div class="flow"></div>
</div>
</div>
<div id="page5" class="page">
<div class="wrap">
<h1>三、对接准备</h1>
<h2 id="page5-1">1、通讯方式</h2>
<p>程序调用时请求接口采用HTTP协议。接口请求参数以及接口请求返回的结果均以#返回值格式,需研发提供下#格式数据为标准。</p>
</div>
<div id="page6">
<div class="wrap">
<h2>2、加密方式</h2>
<p>程序调用时请求接口采用HTTP协议。接口请求参数以及接口请求返回的结果均以#返回值格式,需研发提供下#格式数据为标准。</p>
</div>
</div>
<div id="page7">
<div class="wrap">
<h1>四、名词解释</h1>
<p>程序调用时请求接口采用HTTP协议。接口请求参数以及接口请求返回的结果均以#返回值格式,需研发提供下#格式数据为标准。</p>
</div>
</div>
</div>
<div id="page8">
<div class="wrap">
<h1>五、对接接口</h1>
<!-- 新建订单 -->
<div class="iterFace_list" >
<h2 id="page8-1" >1、新建订单</h2>
<div class="wrap">
<h3 class="mt3"> 1.1、接口说明</h3>
<table class="inter_table_desc" border="0" cellspacing="0" cellpadding="0" >
<tr>
<th>接口说明</th>
<td >正常接口</td>
</tr>
<tr>
<th>接口地址</th>
<td >/<span th:text="${partnerName}"></span>/1/0</td>
</tr>
</table>
</div>
<div class="wrap">
<h3>1.2、请求参数</h3>
<table class="inter_table" border="0" cellspacing="0" cellpadding="0" >
<tr>
<th th:colspan="3" align="center">参数名</th>
<th align="center">名称</th>
<th align="center">类型</th>
<th align="center">是否必填</th>
<th align="center">特殊规则</th>
<th align="center">说明</th>
</tr>
<tbody>
<tr >
<td align="center">code</td>
<td ></td>
<td ></td>
<td >合作机构编码</td>
<td >String</td>
<td >是</td>
<td ></td>
<td>文字</td>
</tr>
<tr>
<td rowspan="6" align="center">data</td>
</tr>
<tr >
<td >orderId</td>
<td></td>
<td>金云汇系统订单号</td>
<td>String</td>
<td>是</td>
<td></td>
<td>文字</td>
</tr>
<tr >
<td >businessCode</td>
<td></td>
<td >业务编码</td>
<td >String</td>
<td >是</td>
<td></td>
<td>文字</td>
</tr>
<tr>
<td >accessCode</td>
<td></td>
<td >准入编码</td>
<td >String</td>
<td >是</td>
<td></td>
<td>文字</td>
</tr>
<tr>
<td >channelCode</td>
<td></td>
<td> 渠道编码</td>
<td>String</td>
<td>是</td>
<td></td>
<td>文字</td>
</tr>
<tr >
<td >customOrderId</td>
<td></td>
<td>机构唯一标识</td>
<td>String</td>
<td>是</td>
<td></td>
<td>文字</td>
</tr>
</tbody>
</table>
</div>
<div class="wrap">
<h3>1.3、发送样例</h3>
<div class="show_code">
<pre>
<code class="show">
</code>
</pre>
<code style="display: none" class="json" >
{
"code": "e73f7214de5543be0bb9b72cdae7463c",
"data": {
"accessCode": "",
"businessCode": "",
"channelCode": "",
"orderId": 1,
"customOrderId": ""
}
}
</code>
</div>
</div>
<div class="wrap">
<h3>1.4、响应参数</h3>
<table class="inter_table" border="0" cellspacing="0" cellpadding="0">
<tr>
<th align="center">参数名</th>
<th align="center">说明</th>
</tr>
<tr>
<td align="center">code</td>
<td colspan="5">状态码(200代表成功, 1XXX代表错误码)</td>
</tr>
<tr>
<td align="center">message</td>
<td colspan="5">状态码描述</td>
</tr>
<tr>
<td align="center">orderId</td>
<td colspan="5">订单号</td>
</tr>
<tr>
<td align="center">status</td>
<td colspan="5">订单状态(0:进行中,1:订单完成 ,2:拒绝办理,3:订单终止)</td>
</tr>
</table>
</div>
<div class="wrap">
<h3>1.5、返回样例</h3>
<div class="show_code">
<pre>
<code class="show">
</code>
</pre>
<code style="display: none" class="json" >
{
"code":200,
"message":"成功",
"orderId":"15542568760393899",
"status":null
}
</code>
</div>
</div>
</div>
<!-- 查询订单状态 -->
<div class="iterFace_list" >
<h2 id="page8-2" >2、查询订单状态</h2>
<div class="wrap">
<h3 class="mt3"> 2.1、接口说明</h3>
<table class="inter_table_desc" border="0" cellspacing="0" cellpadding="0" >
<tr>
<th>接口说明</th>
<td >正常接口</td>
</tr>
<tr>
<th>接口地址</th>
<td >/<span th:text="${partnerName}"></span>/2/0</td>
</tr>
</table>
</div>
<div class="wrap">
<h3>2.2、请求参数</h3>
<table class="inter_table" border="0" cellspacing="0" cellpadding="0" >
<tr>
<th th:colspan="3" align="center">参数名</th>
<th align="center">名称</th>
<th align="center">类型</th>
<th align="center">是否必填</th>
<th align="center">特殊规则</th>
<th align="center">说明</th>
</tr>
<tbody>
<tr >
<td align="center">code</td>
<td ></td>
<td ></td>
<td >合作机构编码</td>
<td >String</td>
<td >是</td>
<td ></td>
<td>文字</td>
</tr>
<tr>
<td rowspan="6" align="center">data</td>
</tr>
<tr >
<td >orderId</td>
<td></td>
<td>金云汇系统订单号</td>
<td>String</td>
<td>是</td>
<td></td>
<td>文字</td>
</tr>
<tr >
<td >businessCode</td>
<td></td>
<td >业务编码</td>
<td >String</td>
<td >是</td>
<td></td>
<td>文字</td>
</tr>
<tr>
<td >accessCode</td>
<td></td>
<td >准入编码</td>
<td >String</td>
<td >是</td>
<td></td>
<td>文字</td>
</tr>
<tr>
<td >channelCode</td>
<td></td>
<td> 渠道编码</td>
<td>String</td>
<td>是</td>
<td></td>
<td>文字</td>
</tr>
</tbody>
</table>
</div>
<div class="wrap">
<h3>2.3、发送样例</h3>
<div class="show_code">
<pre>
<code class="show">
</code>
</pre>
<code style="display: none" class="json" >
{
"code": "e73f7214de5543be0bb9b72cdae7463c",
"data": {
"accessCode": "",
"businessCode": "",
"channelCode": "",
"orderId": 1
}
}
</code>
</div>
</div>
<div class="wrap">
<h3>2.4、响应参数</h3>
<table class="inter_table" border="0" cellspacing="0" cellpadding="0">
<tr>
<th align="center">参数名</th>
<th align="center">说明</th>
</tr>
<tr>
<td align="center">code</td>
<td colspan="5">状态码(200代表成功, 1XXX代表错误码)</td>
</tr>
<tr>
<td align="center">message</td>
<td colspan="5">状态码描述</td>
</tr>
<tr>
<td align="center">orderId</td>
<td colspan="5">订单号</td>
</tr>
<tr>
<td align="center">status</td>
<td colspan="5">订单状态(0:进行中,1:订单完成 ,2:拒绝办理,3:订单终止)</td>
</tr>
</table>
</div>
<div class="wrap">
<h3>2.5、返回样例</h3>
<div class="show_code">
<pre>
<code class="show">
</code>
</pre>
<code style="display: none" class="json" >
{
"code":200,
"message":"成功",
"orderId":"15542568760393899",
"status":null
}
</code>
</div>
</div>
</div>
<!-- 流程内取消订单 -->
<div class="iterFace_list" >
<h2 id="page8-3" >3、流程内取消订单</h2>
<div class="wrap">
<h3 class="mt3"> 3.1、接口说明</h3>
<table class="inter_table_desc" border="0" cellspacing="0" cellpadding="0" >
<tr>
<th>接口说明</th>
<td >正常接口</td>
</tr>
<tr>
<th>接口地址</th>
<td >/<span th:text="${partnerName}"></span>/3/0</td>
</tr>
</table>
</div>
<div class="wrap">
<h3>3.2、请求参数</h3>
<table class="inter_table" border="0" cellspacing="0" cellpadding="0" >
<tr>
<th th:colspan="3" align="center">参数名</th>
<th align="center">名称</th>
<th align="center">类型</th>
<th align="center">是否必填</th>
<th align="center">特殊规则</th>
<th align="center">说明</th>
</tr>
<tbody>
<tr >
<td align="center">code</td>
<td ></td>
<td ></td>
<td >合作机构编码</td>
<td >String</td>
<td >是</td>
<td ></td>
<td>文字</td>
</tr>
<tr>
<td rowspan="6" align="center">data</td>
</tr>
<tr >
<td >orderId</td>
<td></td>
<td>金云汇系统订单号</td>
<td>String</td>
<td>是</td>
<td></td>
<td>文字</td>
</tr>
<tr >
<td >businessCode</td>
<td></td>
<td >业务编码</td>
<td >String</td>
<td >是</td>
<td></td>
<td>文字</td>
</tr>
<tr>
<td >accessCode</td>
<td></td>
<td >准入编码</td>
<td >String</td>
<td >是</td>
<td></td>
<td>文字</td>
</tr>
<tr>
<td >channelCode</td>
<td></td>
<td> 渠道编码</td>
<td>String</td>
<td>是</td>
<td></td>
<td>文字</td>
</tr>
</tbody>
</table>
</div>
<div class="wrap">
<h3>3.3、发送样例</h3>
<div class="show_code">
<pre>
<code class="show">
</code>
</pre>
<code style="display: none" class="json" >
{
"code": "e73f7214de5543be0bb9b72cdae7463c",
"data": {
"accessCode": "",
"businessCode": "",
"channelCode": "",
"orderId": 1
}
}
</code>
</div>
</div>
<div class="wrap">
<h3>3.4、响应参数</h3>
<table class="inter_table" border="0" cellspacing="0" cellpadding="0">
<tr>
<th align="center">参数名</th>
<th align="center">说明</th>
</tr>
<tr>
<td align="center">code</td>
<td colspan="5">状态码(200代表成功, 1XXX代表错误码)</td>
</tr>
<tr>
<td align="center">message</td>
<td colspan="5">状态码描述</td>
</tr>
<tr>
<td align="center">orderId</td>
<td colspan="5">订单号</td>
</tr>
<tr>
<td align="center">status</td>
<td colspan="5">订单状态(0:进行中,1:订单完成 ,2:拒绝办理,3:订单终止)</td>
</tr>
</table>
</div>
<div class="wrap">
<h3>3.5、返回样例</h3>
<div class="show_code">
<pre>
<code class="show">
</code>
</pre>
<code style="display: none" class="json" >
{
"code":200,
"message":"成功",
"orderId":"15542568760393899",
"status":null
}
</code>
</div>
</div>
</div>
<!-- 流程外取消订单 -->
<div class="iterFace_list" >
<h2 id="page8-4" >4、流程外取消订单</h2>
<div class="wrap">
<h3 class="mt3"> 4.1、接口说明</h3>
<table class="inter_table_desc" border="0" cellspacing="0" cellpadding="0" >
<tr>
<th>接口说明</th>
<td >正常接口</td>
</tr>
<tr>
<th>接口地址</th>
<td >/<span th:text="${partnerName}"></span>/4/0</td>
</tr>
</table>
</div>
<div class="wrap">
<h3>4.2、请求参数</h3>
<table class="inter_table" border="0" cellspacing="0" cellpadding="0" >
<tr>
<th th:colspan="3" align="center">参数名</th>
<th align="center">名称</th>
<th align="center">类型</th>
<th align="center">是否必填</th>
<th align="center">特殊规则</th>
<th align="center">说明</th>
</tr>
<tbody>
<tr >
<td align="center">code</td>
<td ></td>
<td ></td>
<td >合作机构编码</td>
<td >String</td>
<td >是</td>
<td ></td>
<td>文字</td>
</tr>
<tr>
<td rowspan="6" align="center">data</td>
</tr>
<tr >
<td >orderId</td>
<td></td>
<td>金云汇系统订单号</td>
<td>String</td>
<td>是</td>
<td></td>
<td>文字</td>
</tr>
<tr >
<td >businessCode</td>
<td></td>
<td >业务编码</td>
<td >String</td>
<td >是</td>
<td></td>
<td>文字</td>
</tr>
<tr>
<td >accessCode</td>
<td></td>
<td >准入编码</td>
<td >String</td>
<td >是</td>
<td></td>
<td>文字</td>
</tr>
<tr>
<td >channelCode</td>
<td></td>
<td> 渠道编码</td>
<td>String</td>
<td>是</td>
<td></td>
<td>文字</td>
</tr>
</tbody>
</table>
</div>
<div class="wrap">
<h3>4.3、发送样例</h3>
<div class="show_code">
<pre>
<code class="show">
</code>
</pre>
<code style="display: none" class="json" >
{
"code": "e73f7214de5543be0bb9b72cdae7463c",
"data": {
"accessCode": "",
"businessCode": "",
"channelCode": "",
"orderId": 1
}
}
</code>
</div>
</div>
<div class="wrap">
<h3>4.4、响应参数</h3>
<table class="inter_table" border="0" cellspacing="0" cellpadding="0">
<tr>
<th align="center">参数名</th>
<th align="center">说明</th>
</tr>
<tr>
<td align="center">code</td>
<td colspan="5">状态码(200代表成功, 1XXX代表错误码)</td>
</tr>
<tr>
<td align="center">message</td>
<td colspan="5">状态码描述</td>
</tr>
<tr>
<td align="center">orderId</td>
<td colspan="5">订单号</td>
</tr>
<tr>
<td align="center">status</td>
<td colspan="5">订单状态(0:进行中,1:订单完成 ,2:拒绝办理,3:订单终止)</td>
</tr>
</table>
</div>
<div class="wrap">
<h3>4.5、返回样例</h3>
<div class="show_code">
<pre>
<code class="show">
</code>
</pre>
<code style="display: none" class="json" >
{
"code":200,
"message":"成功",
"orderId":"15542568760393899",
"status":null
}
</code>
</div>
</div>
</div>
<!-- 遍历接口获取值 -->
<div class="iterFace_list" th:each="mapEntry: ${file}">
<h2 th:id="${mapEntry.pageId}" >
<!-- <h2 th:id="${mapEntry.pageId}" th:text="${mapEntry.apiName}"> -->
<span th:text="${mapEntry.apiNameNum}"></span>
<span >、</span>
<span th:text="${mapEntry.apiName}"></span>
</h2>
<!-- <h2 th:id="page8-1" th:text="${mapEntry.apiName}">1、#接口名称#</h2> -->
<div class="wrap">
<h3 class="mt3"> <span th:text="${mapEntry.apiNameNum}"></span>.1、接口说明</h3>
<table class="inter_table_desc" border="0" cellspacing="0" cellpadding="0" th:each="cate2:${mapEntry.apDocumentParameterVo}">
<tr>
<th>接口说明</th>
<td th:text="${cate2.apiRemake}">#进件接口管理中对应接口的接口描述+接口类型:补录接口或正常接口#</td>
</tr>
<tr>
<th>接口地址</th>
<td th:text="${cate2.apiAddress}">#进件接口管理中对应接口的接口地址+接口的参数名#</td>
</tr>
</table>
</div>
<div class="wrap">
<h3><span th:text="${mapEntry.apiNameNum}"></span>.2、请求参数</h3>
<table class="inter_table" border="0" cellspacing="0" cellpadding="0" >
<tr>
<th th:colspan="3" align="center">参数名</th>
<th align="center">名称</th>
<th align="center">类型</th>
<th align="center">是否必填</th>
<th align="center">特殊规则</th>
<th align="center">说明</th>
</tr>
<tbody th:each="cate2:${mapEntry.apDocumentParameterVo}">
<tr >
<td align="center">code</td>
<td ></td>
<td ></td>
<td >合作机构编码</td>
<td >String</td>
<td >是</td>
<td ></td>
<td>文字</td>
</tr>
<tr>
<td th:rowspan="${cate2.dataCount}" align="center">data</td>
</tr>
<tr th:each="cate3:${cate2.data}">
<td >orderId</td>
<td></td>
<td>订单号</td>
<td>String</td>
<td>是</td>
<td></td>
<td>文字</td>
</tr>
<tr th:each="cate3:${cate2.data}">
<td >businessCode</td>
<td></td>
<td >业务编码</td>
<td >String</td>
<td >是</td>
<td></td>
<td>文字</td>
</tr>
<tr th:each="cate3:${cate2.data}">
<td >accessCode</td>
<td></td>
<td >准入编码</td>
<td >String</td>
<td >是</td>
<td></td>
<td>文字</td>
</tr>
<tr th:each="cate3:${cate2.data}">
<td >channelCode</td>
<td></td>
<td> 渠道编码</td>
<td>String</td>
<td>是</td>
<td></td>
<td>文字</td>
</tr>
<!-- 主借款人信息 -->
<tr th:each="cate3:${cate2.data}">
<td th:rowspan="${cate3.mainBorrowerCount}">mainBorrower</td>
<div th:if="${#arrays.isEmpty(cate3.mainBorrower)}">
<td> </td>
<td>主借款人信息</td>
<td>json</td>
<td>是</td>
<td> </td>
<td>json对象</td>
</div>
</tr>
<div th:each="cate3:${cate2.data}">
<div th:each="user:${cate3.mainBorrower}" >
<tr>
<td th:text="${user?.paramName}"></td>
<td th:text="${user?.filedNameType}"></td>
<!-- th:switch / th:case -->
<div th:switch="${user?.apiReceiveType}">
<td th:case="'1'">String </td>
<td th:case="'2'">String </td>
<td th:case="'3'">String </td>
<td th:case="'4'">Number </td>
<td th:case="'5'">JSONArray</td>
<td th:case="'6'">String</td>
<td th:case="*">String</td>
</div>
<td th:text="${user?.required}==0?'否':'是'"></td>
<td th:text="${user?.specialRules}"></td>
<div th:switch="${user?.apiReceiveType}">
<td th:case="'1'">图片 </td>
<td th:case="'2'">视频/音频 </td>
<td th:case="'3'">文字 </td>
<td th:case="'4'">数值 </td>
<td th:case="'5'">文件夹 </td>
<td th:case="'6'">PDF</td>
<td th:case="*">文字</td>
</div>
</tr>
</div>
</div>
<!-- 反担保人信息 -->
<tr th:each="cate3:${cate2.data}">
<td th:rowspan="${cate3.guarantorCount}">guarantor</td>
<div th:if="${#arrays.isEmpty(cate3.guarantor)}">
<td> </td>
<td>反担保人信息</td>
<td>json</td>
<td>是</td>
<td> </td>
<td>JSONArray</td>
</div>
</tr>
<div th:each="cate3:${cate2.data}">
<div th:each="user:${cate3.guarantor}" >
<tr>
<td th:text="${user?.paramName}"></td>
<td th:text="${user?.filedNameType}"></td>
<div th:switch="${user?.apiReceiveType}">
<td th:case="'1'">String </td>
<td th:case="'2'">String </td>
<td th:case="'3'">String </td>
<td th:case="'4'">Number </td>
<td th:case="'5'">JSONArray </td>
<td th:case="'6'">String</td>
<td th:case="*">String</td>
</div>
<td th:text="${user?.required}==0?'否':'是'"></td>
<td th:text="${user?.specialRules}"></td>
<div th:switch="${user?.apiReceiveType}">
<td th:case="'1'">图片 </td>
<td th:case="'2'">视频/音频 </td>
<td th:case="'3'">文字 </td>
<td th:case="'4'">数值 </td>
<td th:case="'5'">文件夹 </td>
<td th:case="'6'">PDF</td>
<td th:case="*">文字</td>
</div>
</tr>
</div>
</div>
<!-- 共同还款人信息-->
<tr th:each="cate3:${cate2.data}">
<td th:rowspan="${cate3.coPayerCount}">coPayer</td>
<div th:if="${#arrays.isEmpty(cate3.coPayer)}">
<td> </td>
<td>共同还款人信息</td>
<td>json</td>
<td>是</td>
<td> </td>
<td>JSONArray</td>
</div>
</tr>
<div th:each="cate3:${cate2.data}">
<div th:each="user:${cate3.coPayer}" >
<tr>
<td th:text="${user?.paramName}"></td>
<td th:text="${user?.filedNameType}"></td>
<div th:switch="${user?.apiReceiveType}">
<td th:case="'1'">String </td>
<td th:case="'2'">String </td>
<td th:case="'3'">String </td>
<td th:case="'4'">Number </td>
<td th:case="'5'">JSONArray </td>
<td th:case="'6'">String</td>
<td th:case="*">String</td>
</div>
<td th:text="${user?.required}==0?'否':'是'"></td>
<td th:text="${user?.specialRules}"></td>
<div th:switch="${user?.apiReceiveType}">
<td th:case="'1'">图片 </td>
<td th:case="'2'">视频/音频 </td>
<td th:case="'3'">文字 </td>
<td th:case="'4'">数值 </td>
<td th:case="'5'">文件夹 </td>
<td th:case="'6'">PDF</td>
<td th:case="*">文字</td>
</div>
</tr>
</div>
</div>
<!-- order信息 -->
<tr th:each="cate3:${cate2.data}">
<td th:rowspan="${cate3.orderCount}">order</td>
<div th:if="${#arrays.isEmpty(cate3.order)}">
<td> </td>
<td>订单信息</td>
<td>json</td>
<td>是</td>
<td> </td>
<td>json对象</td>
</div>
</tr>
<div th:each="cate3:${cate2.data}">
<div th:each="user:${cate3.order}" >
<tr>
<td th:text="${user?.paramName}"></td>
<td th:text="${user?.filedNameType}"></td>
<div th:switch="${user?.apiReceiveType}">
<td th:case="'1'">String </td>
<td th:case="'2'">String </td>
<td th:case="'3'">String </td>
<td th:case="'4'">Number </td>
<td th:case="'5'">JSONArray</td>
<td th:case="'6'">String</td>
<td th:case="*">String</td>
</div>
<td th:text="${user?.required}==0?'否':'是'"></td>
<td th:text="${user?.specialRules}"></td>
<div th:switch="${user?.apiReceiveType}">
<td th:case="'1'">图片 </td>
<td th:case="'2'">视频/音频 </td>
<td th:case="'3'">文字 </td>
<td th:case="'4'">数值 </td>
<td th:case="'5'">文件夹 </td>
<td th:case="'6'">PDF</td>
<td th:case="*">文字</td>
</div>
</tr>
</div>
</div>
<tr>
<td align="center">sign</td>
<td></td>
<td></td>
<td>签名</td>
<td>String</td>
<td>是</td>
<td></td>
<td>文字</td>
</tr>
</tbody>
</table>
</div>
<div class="wrap">
<h3><span th:text="${mapEntry.apiNameNum}"></span>.3、发送样例</h3>
<div class="show_code">
<pre>
<code class="show">
</code>
</pre>
<!-- <code style="display: none" class="json" th:text="${mapEntry.backJson}">
--> <code style="display: none" class="json" th:text="${mapEntry.infoJson}" >
{
"code":200,
"message":"成功",
"orderId":"15542568760393899",
"status":null
}
</code>
</div>
</div>
<div class="wrap">
<h3><span th:text="${mapEntry.apiNameNum}"></span>.4、响应参数</h3>
<table class="inter_table" border="0" cellspacing="0" cellpadding="0">
<tr>
<th align="center">参数名</th>
<th align="center">说明</th>
</tr>
<tr>
<td align="center">code</td>
<td colspan="5">状态码(200代表成功, 1XXX代表错误码)</td>
</tr>
<tr>
<td align="center">message</td>
<td colspan="5">状态码描述</td>
</tr>
<tr>
<td align="center">orderId</td>
<td colspan="5">订单号</td>
</tr>
<tr>
<td align="center">status</td>
<td colspan="5">订单状态(0:进行中,1:订单完成 ,2:拒绝办理,3:订单终止)</td>
</tr>
</table>
</div>
<div class="wrap">
<h3><span th:text="${mapEntry.apiNameNum}"></span>.5、返回样例</h3>
<div class="show_code">
<pre>
<code class="show">
</code>
</pre>
<!-- <code style="display: none" class="json" th:text="${mapEntry.backJson}">
--> <code style="display: none" class="json" >
{
"code":200,
"message":"成功",
"orderId":"15542568760393899",
"status":null
}
</code>
</div>
</div>
</div>
</div>
</div>
<div id="page9">
<div class="wrap" >
<h1>六、错误码</h1>
<table class="mt3" border="0" cellspacing="0" cellpadding="0">
<tr>
<th>错误码</th>
<th>错误信息</th>
</tr>
<tr th:each="errorCodes: ${errorCode}">
<td th:text="${errorCodes.code}"></td>
<td th:text="${errorCodes.name}"></td>
</tr>
</table>
</div>
</div>
<div id="page10" class="page">
<div class="wrap">
<h1>七、常见问题</h1>
<p></p>
</div>
</div>
</div>
</body>
</html>
controller
@RequestMapping(value = "/download")
public void download(HttpServletRequest request, HttpServletResponse response, Integer processId,
Integer basePartnerId) throws ServletException, IOException {
// 查询数据库中各接口的参数
List<ApiBackVo> selectFiledList = apiProcessCodeService.selectFiledList(processId, basePartnerId);
// 错误吗
List<ApiFileTypeEnumVo> errorCode = ergodicEnumData();
Context context = new Context();
context.setVariable("file", selectFiledList);
context.setVariable("formatTime", formatTime);
context.setVariable("apiName", apiName);
context.setVariable("partnerName", partnerName);
context.setVariable("errorCode", errorCode);
File fileExist = (File)new File(path);
if (!fileExist.exists()) {
fileExist.mkdirs();
}
String writerFileName = basePartnerId + "-" + processId + "-" + "example.html";
File writerFile = new File(path + writerFileName);
if (writerFile.exists()) {
boolean delete = writerFile.delete();
log.info(basePartnerId + "-" + processId + "-文件删除是否成功:" + delete);
}
BufferedWriter fileWriter =
new BufferedWriter(new OutputStreamWriter(new FileOutputStream(path + writerFileName, true), "UTF-8"));
templateEngine.process("example", context, fileWriter);
fileWriter.close();
// 设置要导出的文件的名字
String fileName = "接口文档.zip";
String userAgent = request.getHeader("user-agent").toLowerCase();
if (userAgent.contains("msie") || userAgent.contains("trident")) {
// win10 ie edge 浏览器 和其他系统的ie
fileName = URLEncoder.encode(fileName, "UTF-8");
} else {
// 其他的浏览器
fileName = new String(fileName.getBytes("UTF-8"), "ISO-8859-1");
}
response.setContentType("application/octet-stream");
response.setHeader("Content-disposition", "attachment;filename=" + fileName);
ZipOutputStream zipOutputStream = new ZipOutputStream(response.getOutputStream());
// 本地文件得物理路径
List<String> list = new ArrayList<>();
list.add(writerFileName);
list.add("city.json");
list.add("flow.jpg");
for (String string : list) {
File file = (File)new File(path + string);
if (StringUtils.equals("flow", string.substring(0, string.indexOf(".")))) {
zipFile(file, "系统对接流程图", zipOutputStream);
} else {
zipFile(file, string.substring(0, string.indexOf(".")), zipOutputStream);
}
}
zipOutputStream.close();
}
/**
* 压缩文件
*
* @param inputFile 待压缩的文件
* @param a 区分压缩包文件名相同
* @param identity 借款人类型名称
* @param materialsName 类别,比如身份证正面、反面等
* @param name 借款人姓名
* @param outputstream zip包流
* @throws IOException
* @throws ServletException
*/
private static void zipFile(File inputFile, String name, ZipOutputStream outputstream)
throws IOException, ServletException {
InputStream in = null;
try {
if (inputFile.exists()) {
if (inputFile.isFile()) {
String fileName = inputFile.getName();
String Photoname =
"跨机构进件api接口对接文档" + File.separator + name + fileName.substring(fileName.lastIndexOf("."));
byte[] buff = new byte[1024];
in = new FileInputStream(inputFile);
ZipEntry entry = new ZipEntry(Photoname);
outputstream.putNextEntry(entry);
int len;
while ((len = in.read(buff, 0, 1024)) != -1) {
outputstream.write(buff, 0, len);
}
}
} else {
log.error("文件不存在!" + inputFile);
}
} catch (IOException e) {
log.error("下载出错!", e);
} finally {
if (in != null) {
in.close();
}
}
}