合同增加文件名称字段,并增加下载附件功能
This commit is contained in:
parent
a9fa3fc713
commit
e2f50b32e6
|
|
@ -110,4 +110,36 @@ public class CommonController
|
|||
|
||||
FileUtils.writeBytes(downloadPath, response.getOutputStream());
|
||||
}
|
||||
|
||||
/**
|
||||
* 通用下载请求
|
||||
*
|
||||
* @param filePath 文件路径
|
||||
* @param realFileName 文件名称
|
||||
* @param delete 是否删除
|
||||
*/
|
||||
@GetMapping("common/download2")
|
||||
public void fileDownload(String filePath, String realFileName, Boolean delete, HttpServletResponse response, HttpServletRequest request)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!FileUtils.isValidFilename(realFileName))
|
||||
{
|
||||
throw new Exception(StringUtils.format("文件名称({})非法,不允许下载。 ", realFileName));
|
||||
}
|
||||
|
||||
response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
|
||||
FileUtils.setAttachmentResponseHeader(response, realFileName);
|
||||
|
||||
FileUtils.writeBytes(filePath, response.getOutputStream());
|
||||
if (delete)
|
||||
{
|
||||
FileUtils.deleteFile(filePath);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
log.error("下载文件失败", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -96,9 +96,9 @@ shiro:
|
|||
# 首页地址
|
||||
indexUrl: /index
|
||||
# 验证码开关
|
||||
captchaEnabled: true
|
||||
captchaEnabled: false
|
||||
# 验证码类型 math 数组计算 char 字符
|
||||
captchaType: math
|
||||
captchaType: char
|
||||
cookie:
|
||||
# 设置Cookie的域名 默认空,即当前访问的域名
|
||||
domain:
|
||||
|
|
|
|||
|
|
@ -482,7 +482,7 @@ function uploadFile(async, filePathId, fileNameId) {
|
|||
$('#' + filePathId).val(result.url);
|
||||
}
|
||||
if (fileNameId) {
|
||||
$('#' + fileNameId).val(result.fileName);
|
||||
$('#' + fileNameId).val(result.originalFilename);
|
||||
}
|
||||
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -39,9 +39,12 @@ public class ContractTemplate extends BaseEntity
|
|||
private Integer hits;
|
||||
|
||||
/** 附件下载(多个地址用,分隔) */
|
||||
@Excel(name = "附件下载", readConverterExp = "多=个地址用,分隔")
|
||||
@Excel(name = "附件地址")
|
||||
private String enclosureUrl;
|
||||
|
||||
@Excel(name = "附件名称")
|
||||
private String enclosureName;
|
||||
|
||||
/** 状态(0正常 1停用) */
|
||||
@Excel(name = "状态", readConverterExp = "0=正常,1=停用")
|
||||
private String status;
|
||||
|
|
@ -131,6 +134,14 @@ public class ContractTemplate extends BaseEntity
|
|||
return delFlag;
|
||||
}
|
||||
|
||||
public String getEnclosureName() {
|
||||
return enclosureName;
|
||||
}
|
||||
|
||||
public void setEnclosureName(String enclosureName) {
|
||||
this.enclosureName = enclosureName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<result property="content" column="content" />
|
||||
<result property="hits" column="hits" />
|
||||
<result property="enclosureUrl" column="enclosure_url" />
|
||||
<result property="enclosureName" column="enclosure_name" />
|
||||
<result property="status" column="status" />
|
||||
<result property="delFlag" column="del_flag" />
|
||||
<result property="createBy" column="create_by" />
|
||||
|
|
@ -22,7 +23,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
</resultMap>
|
||||
|
||||
<sql id="selectContractTemplateVo">
|
||||
select id, type, title, introduction, content, hits, enclosure_url, status, del_flag, create_by, create_time, update_by, update_time, remark from contract_template
|
||||
select id, type, title, introduction, content, hits,enclosure_name, enclosure_url, status, del_flag, create_by, create_time, update_by, update_time, remark from contract_template
|
||||
</sql>
|
||||
|
||||
<select id="selectContractTemplateList" parameterType="ContractTemplate" resultMap="ContractTemplateResult">
|
||||
|
|
@ -52,6 +53,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<if test="content != null and content != ''">content,</if>
|
||||
<if test="hits != null">hits,</if>
|
||||
<if test="enclosureUrl != null and enclosureUrl != ''">enclosure_url,</if>
|
||||
<if test="enclosureName != null and enclosureName != ''">enclosure_name,</if>
|
||||
<if test="status != null">status,</if>
|
||||
<if test="delFlag != null">del_flag,</if>
|
||||
<if test="createBy != null">create_by,</if>
|
||||
|
|
@ -67,6 +69,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<if test="content != null and content != ''">#{content},</if>
|
||||
<if test="hits != null">#{hits},</if>
|
||||
<if test="enclosureUrl != null and enclosureUrl != ''">#{enclosureUrl},</if>
|
||||
<if test="enclosureName != null and enclosureName != ''">#{enclosureName},</if>
|
||||
<if test="status != null">#{status},</if>
|
||||
<if test="delFlag != null">#{delFlag},</if>
|
||||
<if test="createBy != null">#{createBy},</if>
|
||||
|
|
@ -86,6 +89,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<if test="content != null and content != ''">content = #{content},</if>
|
||||
<if test="hits != null">hits = #{hits},</if>
|
||||
<if test="enclosureUrl != null and enclosureUrl != ''">enclosure_url = #{enclosureUrl},</if>
|
||||
<if test="enclosureName != null and enclosureName != ''">enclosure_name = #{enclosureName},</if>
|
||||
<if test="status != null">status = #{status},</if>
|
||||
<if test="delFlag != null">del_flag = #{delFlag},</if>
|
||||
<if test="createBy != null">create_by = #{createBy},</if>
|
||||
|
|
|
|||
|
|
@ -46,6 +46,7 @@
|
|||
<div class="col-sm-8">
|
||||
<input id="filePath" name="filePath" class="form-control" type="file">
|
||||
<input id="enclosureUrl" name="enclosureUrl" type="text" hidden>
|
||||
<input id="enclosureName" name="enclosureName" type="text" hidden>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
|
|
|
|||
|
|
@ -126,7 +126,7 @@
|
|||
actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
|
||||
actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
|
||||
if (row.enclosureUrl) {
|
||||
actions.push('<a class="btn btn-danger btn-xs " href="javascript:void(0)" onclick="$.operate.remove(\'' + row.enclosureUrl + '\')"><i class="fa fa-download"></i>下载附件</a>');
|
||||
actions.push('<a class="btn btn-danger btn-xs " href="javascript:void(0)" onclick="downLoad(\'' + row.enclosureUrl + '\', \'' + row.enclosureName+ '\')"><i class="fa fa-download"></i>下载附件</a>');
|
||||
}
|
||||
return actions.join('');
|
||||
}
|
||||
|
|
@ -135,8 +135,9 @@
|
|||
$.table.init(options);
|
||||
});
|
||||
|
||||
function downLoad(url) {
|
||||
window.location.href = ctx + "common/download?fileName=" + encodeURI(url) + "&delete=" + true;
|
||||
function downLoad(fileUrl,realFileName) {
|
||||
alert(ctx + "common/download2?filePath = " + fileUrl + "&realFileName=" + encodeURI(realFileName) + "&delete=" + false);
|
||||
window.location.href = ctx + "common/download2?filePath = " + fileUrl + "&realFileName=" + encodeURI(realFileName) + "&delete=" + false;
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
|
|
|
|||
|
|
@ -48,7 +48,8 @@ create table contract_template (
|
|||
introduction text not null comment '简介',
|
||||
content text not null comment '详情内容',
|
||||
hits int (6) default 0 comment '点击量',
|
||||
enclosure_url varchar(500) not null comment '附件下载(多个地址用,分隔)',
|
||||
enclosure_name varchar(60) not null comment '附件名称',
|
||||
enclosure_url varchar(500) not null comment '附件地址',
|
||||
status char(1) default '0' comment '状态(0正常 1停用)',
|
||||
del_flag char(1) default '0' comment '删除标志(0代表存在 2代表删除)',
|
||||
create_by varchar(64) default '' comment '创建者',
|
||||
|
|
|
|||
Loading…
Reference in New Issue