mirror of https://gitee.com/stylefeng/roses
【7.0.4】【util】新增一个下载文件设置头的工具类
parent
5a06086b96
commit
6704c5a5db
|
@ -25,6 +25,9 @@
|
||||||
package cn.stylefeng.roses.kernel.rule.util;
|
package cn.stylefeng.roses.kernel.rule.util;
|
||||||
|
|
||||||
import cn.hutool.core.util.CharsetUtil;
|
import cn.hutool.core.util.CharsetUtil;
|
||||||
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import cn.hutool.core.util.URLUtil;
|
||||||
import cn.hutool.http.ContentType;
|
import cn.hutool.http.ContentType;
|
||||||
import cn.stylefeng.roses.kernel.rule.pojo.response.ErrorResponseData;
|
import cn.stylefeng.roses.kernel.rule.pojo.response.ErrorResponseData;
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
|
@ -79,4 +82,16 @@ public class ResponseRenderUtil {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置渲染文件的头
|
||||||
|
*
|
||||||
|
* @author fengshuonan
|
||||||
|
* @date 2021/7/1 15:01
|
||||||
|
*/
|
||||||
|
public static void setRenderFileHeader(HttpServletResponse response, String fileName) {
|
||||||
|
final String charset = ObjectUtil.defaultIfNull(response.getCharacterEncoding(), CharsetUtil.UTF_8);
|
||||||
|
response.setHeader("Content-Disposition", StrUtil.format("attachment;filename={}", URLUtil.encode(fileName, charset)));
|
||||||
|
response.setContentType("application/octet-stream; charset=utf-8");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue