修复文本文件下载乱码

This commit is contained in:
zhouhao
2017-12-13 17:53:50 +08:00
parent 31fbb867d9
commit da133f769e
2 changed files with 5 additions and 8 deletions

View File

@@ -53,8 +53,8 @@ public abstract class GenericEntityService<E extends GenericEntity<PK>, PK>
*/
protected abstract IDGenerator<PK> getIDGenerator();
@Override
public abstract CrudDao<E, PK> getDao();
// @Override
// public abstract CrudDao<E, PK> getDao();
@Override
public int deleteByPk(PK pk) {

View File

@@ -53,7 +53,7 @@ import static java.util.Optional.ofNullable;
@RestController
@RequestMapping("${hsweb.web.mappings.file:file}")
@Authorize(permission = "file", description = "文件管理")
@Api(value = "文件管理",tags = "文件管理-文件操作")
@Api(value = "文件管理", tags = "文件管理-文件操作")
@SuppressWarnings("all")
public class FileController {
@@ -75,10 +75,6 @@ public class FileController {
this.fileInfoService = fileInfoService;
}
public static void main(String[] args) {
System.out.println(Base64.encodeBase64String("hello".getBytes()));
}
/**
* 构建并下载zip文件.仅支持POST请求
*
@@ -133,7 +129,8 @@ public class FileController {
public void downloadTxt(@ApiParam("文件名") @PathVariable("name") String name,
@ApiParam("文本内容") @RequestParam("text") String text,
HttpServletResponse response) throws IOException {
response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
response.setCharacterEncoding("utf-8");
response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE + "; charset=utf-8");
response.setHeader("Content-disposition", "attachment;filename=" + URLEncoder.encode(name, "utf-8"));
response.getWriter().write(text);
}