Procházet zdrojové kódy

修复文本文件下载乱码

zhouhao před 7 roky
rodič
revize
da133f769e

+ 2 - 2
hsweb-commons/hsweb-commons-service/hsweb-commons-service-simple/src/main/java/org/hswebframework/web/service/GenericEntityService.java

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

+ 3 - 6
hsweb-system/hsweb-system-file/hsweb-system-file-controller/src/main/java/org/hswebframework/web/controller/file/FileController.java

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