From 5b0620f997e1b4ff6ce25970a2b9fabddf0e40e8 Mon Sep 17 00:00:00 2001 From: zhouhao Date: Wed, 13 Dec 2017 11:19:48 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E5=A2=9E=E5=8A=A0UserSetting?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../authorization/UserSettingController.java | 64 +++++++++++++ .../web/dao/authorization/UserSettingDao.java | 11 +++ .../authorization/UserSettingMapper.xml | 68 ++++++++++++++ .../authorization/UserSettingEntity.java | 37 ++++++++ .../authorization/UserSettingService.java | 16 ++++ .../simple/SimpleUserSettingService.java | 90 +++++++++++++++++++ .../starter/AutoSyncPermission.java | 12 +-- 7 files changed, 292 insertions(+), 6 deletions(-) create mode 100644 hsweb-system/hsweb-system-authorization/hsweb-system-authorization-controller/src/main/java/org/hswebframework/web/controller/authorization/UserSettingController.java create mode 100644 hsweb-system/hsweb-system-authorization/hsweb-system-authorization-dao/hsweb-system-authorization-dao-api/src/main/java/org/hswebframework/web/dao/authorization/UserSettingDao.java create mode 100644 hsweb-system/hsweb-system-authorization/hsweb-system-authorization-dao/hsweb-system-authorization-dao-mybatis/src/main/resources/org/hswebframework/web/dao/mybatis/mappers/authorization/UserSettingMapper.xml create mode 100644 hsweb-system/hsweb-system-authorization/hsweb-system-authorization-entity/src/main/java/org/hswebframework/web/entity/authorization/UserSettingEntity.java create mode 100644 hsweb-system/hsweb-system-authorization/hsweb-system-authorization-service/hsweb-system-authorization-service-api/src/main/java/org/hswebframework/web/service/authorization/UserSettingService.java create mode 100644 hsweb-system/hsweb-system-authorization/hsweb-system-authorization-service/hsweb-system-authorization-service-simple/src/main/java/org/hswebframework/web/service/authorization/simple/SimpleUserSettingService.java diff --git a/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-controller/src/main/java/org/hswebframework/web/controller/authorization/UserSettingController.java b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-controller/src/main/java/org/hswebframework/web/controller/authorization/UserSettingController.java new file mode 100644 index 000000000..374634c2d --- /dev/null +++ b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-controller/src/main/java/org/hswebframework/web/controller/authorization/UserSettingController.java @@ -0,0 +1,64 @@ +package org.hswebframework.web.controller.authorization; + +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.hswebframework.web.authorization.Authentication; +import org.hswebframework.web.authorization.User; +import org.hswebframework.web.authorization.annotation.Authorize; +import org.hswebframework.web.entity.authorization.UserSettingEntity; +import org.hswebframework.web.service.authorization.UserSettingService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.ResponseEntity; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +/** + * @author zhouhao + * @since 3.0 + */ +@RestController +@RequestMapping("/user-setting") +@Authorize//(permission = "user-setting", description = "用户配置管理") +@Api(value = "用户配置管理", tags = "用户-用户配置管理") +public class UserSettingController { + + @Autowired + private UserSettingService userSettingService; + + @GetMapping("/me/{key}/{id}") + @Authorize(merge = false) + @ApiOperation("获取当前用户的配置") + public ResponseEntity get(Authentication authentication, + @PathVariable String key, + @PathVariable String id) { + return ResponseEntity.ok(userSettingService.selectByUser(authentication.getUser().getId(), key, id)); + } + + @GetMapping("/me/{key}") + @Authorize(merge = false) + @ApiOperation("获取当前用户的配置列表") + public ResponseEntity> get(Authentication authentication, + @PathVariable String key) { + return ResponseEntity.ok(userSettingService.selectByUser(authentication.getUser().getId(), key)); + } + + @PatchMapping("/me/{key}") + @Authorize(merge = false) + @ApiOperation("获取当前用户的配置列表") + public ResponseEntity save(Authentication authentication, + @PathVariable String key, + @Validated + @RequestBody UserSettingEntity userSettingEntity) { + userSettingEntity.setId(null); + userSettingEntity.setUserId(authentication.getUser().getId()); + userSettingEntity.setKey(key); + UserSettingEntity old = userSettingService.selectByUser(authentication.getUser().getId(), key, userSettingEntity.getSettingId()); + if (old != null) { + userSettingEntity.setId(old.getId()); + } + String id = userSettingService.saveOrUpdate(userSettingEntity); + return ResponseEntity.ok(id); + } +} diff --git a/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-dao/hsweb-system-authorization-dao-api/src/main/java/org/hswebframework/web/dao/authorization/UserSettingDao.java b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-dao/hsweb-system-authorization-dao-api/src/main/java/org/hswebframework/web/dao/authorization/UserSettingDao.java new file mode 100644 index 000000000..36e04edbd --- /dev/null +++ b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-dao/hsweb-system-authorization-dao-api/src/main/java/org/hswebframework/web/dao/authorization/UserSettingDao.java @@ -0,0 +1,11 @@ +package org.hswebframework.web.dao.authorization; + +import org.hswebframework.web.dao.CrudDao; +import org.hswebframework.web.entity.authorization.UserSettingEntity; + +/** + * @author zhouhao + * @since 3.0 + */ +public interface UserSettingDao extends CrudDao { +} diff --git a/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-dao/hsweb-system-authorization-dao-mybatis/src/main/resources/org/hswebframework/web/dao/mybatis/mappers/authorization/UserSettingMapper.xml b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-dao/hsweb-system-authorization-dao-mybatis/src/main/resources/org/hswebframework/web/dao/mybatis/mappers/authorization/UserSettingMapper.xml new file mode 100644 index 000000000..5f90db0f9 --- /dev/null +++ b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-dao/hsweb-system-authorization-dao-mybatis/src/main/resources/org/hswebframework/web/dao/mybatis/mappers/authorization/UserSettingMapper.xml @@ -0,0 +1,68 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + delete from s_user_setting where u_id =#{id} + + + + + + + + + + + + + + + + diff --git a/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-entity/src/main/java/org/hswebframework/web/entity/authorization/UserSettingEntity.java b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-entity/src/main/java/org/hswebframework/web/entity/authorization/UserSettingEntity.java new file mode 100644 index 000000000..072badbe4 --- /dev/null +++ b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-entity/src/main/java/org/hswebframework/web/entity/authorization/UserSettingEntity.java @@ -0,0 +1,37 @@ +package org.hswebframework.web.entity.authorization; + +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import org.hibernate.validator.constraints.NotBlank; +import org.hswebframework.web.commons.entity.SimpleGenericEntity; +import org.hswebframework.web.validator.group.CreateGroup; + +import java.util.Date; + +/** + * @author zhouhao + * @since 3.0 + */ +@Getter +@Setter +@NoArgsConstructor +public class UserSettingEntity extends SimpleGenericEntity { + @NotBlank(groups = CreateGroup.class) + private String userId; + + @NotBlank(groups = CreateGroup.class) + + private String key; + + @NotBlank(groups = CreateGroup.class) + private String settingId; + + @NotBlank(groups = CreateGroup.class) + private String setting; + + private Date createTime; + + private Date updateTime; + +} diff --git a/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-service/hsweb-system-authorization-service-api/src/main/java/org/hswebframework/web/service/authorization/UserSettingService.java b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-service/hsweb-system-authorization-service-api/src/main/java/org/hswebframework/web/service/authorization/UserSettingService.java new file mode 100644 index 000000000..e6b7264ee --- /dev/null +++ b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-service/hsweb-system-authorization-service-api/src/main/java/org/hswebframework/web/service/authorization/UserSettingService.java @@ -0,0 +1,16 @@ +package org.hswebframework.web.service.authorization; + +import org.hswebframework.web.entity.authorization.UserSettingEntity; +import org.hswebframework.web.service.CrudService; + +import java.util.List; + +/** + * @author zhouhao + * @since 3.0 + */ +public interface UserSettingService extends CrudService { + List selectByUser(String userId, String key); + + UserSettingEntity selectByUser(String userId, String key, String settingId); +} diff --git a/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-service/hsweb-system-authorization-service-simple/src/main/java/org/hswebframework/web/service/authorization/simple/SimpleUserSettingService.java b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-service/hsweb-system-authorization-service-simple/src/main/java/org/hswebframework/web/service/authorization/simple/SimpleUserSettingService.java new file mode 100644 index 000000000..cfaf79298 --- /dev/null +++ b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-service/hsweb-system-authorization-service-simple/src/main/java/org/hswebframework/web/service/authorization/simple/SimpleUserSettingService.java @@ -0,0 +1,90 @@ +package org.hswebframework.web.service.authorization.simple; + +import org.hswebframework.web.dao.authorization.UserSettingDao; +import org.hswebframework.web.entity.authorization.UserSettingEntity; +import org.hswebframework.web.id.IDGenerator; +import org.hswebframework.web.service.EnableCacheGenericEntityService; +import org.hswebframework.web.service.authorization.UserSettingService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.cache.annotation.CacheConfig; +import org.springframework.cache.annotation.CacheEvict; +import org.springframework.cache.annotation.Cacheable; +import org.springframework.cache.annotation.Caching; +import org.springframework.stereotype.Service; + +import java.util.List; +import java.util.Objects; + +/** + * @author zhouhao + * @since 3.0 + */ +@Service +@CacheConfig(cacheNames = "user-setting") +public class SimpleUserSettingService extends EnableCacheGenericEntityService + implements UserSettingService { + + @Autowired + private UserSettingDao userSettingDao; + + @Override + protected IDGenerator getIDGenerator() { + return IDGenerator.MD5; + } + + @Override + public UserSettingDao getDao() { + return userSettingDao; + } + + @Override + @Cacheable(key = "'user:'+#userId+'.'+#key") + public List selectByUser(String userId, String key) { + Objects.requireNonNull(userId); + Objects.requireNonNull(key); + + return createQuery().where("userId", userId).and("key", key).listNoPaging(); + } + + @Override + @Cacheable(key = "'user:'+#userId+'.'+#key+'.'+#settingId") + public UserSettingEntity selectByUser(String userId, String key, String settingId) { + Objects.requireNonNull(userId); + Objects.requireNonNull(key); + Objects.requireNonNull(settingId); + return createQuery().where("userId", userId).and("key", key).and("settingId", settingId).single(); + } + + @Override + @Caching( + evict = { + @CacheEvict(key = "'user:'+#entity.userId+'.'+#entity.key+'.'+#entity.settingId"), + @CacheEvict(key = "'user:'+#entity.userId+'.'+#entity.key") + } + ) + public String insert(UserSettingEntity entity) { + return super.insert(entity); + } + + @Override + @Caching( + evict = { + @CacheEvict(key = "'user:'+#entity.userId+'.'+#entity.key+'.'+#entity.settingId"), + @CacheEvict(key = "'user:'+#entity.userId+'.'+#entity.key") + } + ) + public String saveOrUpdate(UserSettingEntity entity) { + return super.saveOrUpdate(entity); + } + + @Override + @Caching( + evict = { + @CacheEvict(key = "'user:'+#entity.userId+'.'+#entity.key+'.'+#entity.settingId"), + @CacheEvict(key = "'user:'+#entity.userId+'.'+#entity.key") + } + ) + public int updateByPk(String id, UserSettingEntity entity) { + return super.updateByPk(id, entity); + } +} diff --git a/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-starter/src/main/java/org/hswebframework/web/authorization/starter/AutoSyncPermission.java b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-starter/src/main/java/org/hswebframework/web/authorization/starter/AutoSyncPermission.java index 41517ff71..d9d9a3af6 100644 --- a/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-starter/src/main/java/org/hswebframework/web/authorization/starter/AutoSyncPermission.java +++ b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-starter/src/main/java/org/hswebframework/web/authorization/starter/AutoSyncPermission.java @@ -111,12 +111,13 @@ public class AutoSyncPermission implements ApplicationListener oldAction = oldPermission.getActions(); - if (oldAction == null) { - oldAction = new ArrayList<>(); + Set oldAction = new HashSet<>(); + if (oldPermission.getActions() != null) { + oldAction.addAll(oldPermission.getActions()); } Map actionCache = oldAction - .stream().collect(Collectors.toMap(ActionEntity::getAction, Function.identity())); + .stream() + .collect(Collectors.toMap(ActionEntity::getAction, Function.identity())); boolean permissionChanged = false; for (ActionEntity actionEntity : permission.getActions()) { //添加新的action到旧的action @@ -126,10 +127,9 @@ public class AutoSyncPermission implements ApplicationListener(oldAction)); permissionService.updateByPk(oldPermission.getId(), oldPermission); } - actionCache.clear(); } From 9fceb99bc1c15966e0a914e4bd1421fa09534656 Mon Sep 17 00:00:00 2001 From: zhouhao Date: Wed, 13 Dec 2017 17:53:07 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E4=BC=98=E5=8C=96=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../authorization/UserSettingController.java | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-controller/src/main/java/org/hswebframework/web/controller/authorization/UserSettingController.java b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-controller/src/main/java/org/hswebframework/web/controller/authorization/UserSettingController.java index 374634c2d..2b3391a4c 100644 --- a/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-controller/src/main/java/org/hswebframework/web/controller/authorization/UserSettingController.java +++ b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-controller/src/main/java/org/hswebframework/web/controller/authorization/UserSettingController.java @@ -3,12 +3,11 @@ package org.hswebframework.web.controller.authorization; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.hswebframework.web.authorization.Authentication; -import org.hswebframework.web.authorization.User; import org.hswebframework.web.authorization.annotation.Authorize; +import org.hswebframework.web.controller.message.ResponseMessage; import org.hswebframework.web.entity.authorization.UserSettingEntity; import org.hswebframework.web.service.authorization.UserSettingService; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.ResponseEntity; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; @@ -30,24 +29,24 @@ public class UserSettingController { @GetMapping("/me/{key}/{id}") @Authorize(merge = false) @ApiOperation("获取当前用户的配置") - public ResponseEntity get(Authentication authentication, - @PathVariable String key, - @PathVariable String id) { - return ResponseEntity.ok(userSettingService.selectByUser(authentication.getUser().getId(), key, id)); + public ResponseMessage get(Authentication authentication, + @PathVariable String key, + @PathVariable String id) { + return ResponseMessage.ok(userSettingService.selectByUser(authentication.getUser().getId(), key, id)); } @GetMapping("/me/{key}") @Authorize(merge = false) @ApiOperation("获取当前用户的配置列表") - public ResponseEntity> get(Authentication authentication, + public ResponseMessage> get(Authentication authentication, @PathVariable String key) { - return ResponseEntity.ok(userSettingService.selectByUser(authentication.getUser().getId(), key)); + return ResponseMessage.ok(userSettingService.selectByUser(authentication.getUser().getId(), key)); } @PatchMapping("/me/{key}") @Authorize(merge = false) @ApiOperation("获取当前用户的配置列表") - public ResponseEntity save(Authentication authentication, + public ResponseMessage save(Authentication authentication, @PathVariable String key, @Validated @RequestBody UserSettingEntity userSettingEntity) { @@ -59,6 +58,6 @@ public class UserSettingController { userSettingEntity.setId(old.getId()); } String id = userSettingService.saveOrUpdate(userSettingEntity); - return ResponseEntity.ok(id); + return ResponseMessage.ok(id); } } From 31fbb867d9d823afc5e57bb0d0d014c07f0c9c4c Mon Sep 17 00:00:00 2001 From: zhouhao Date: Wed, 13 Dec 2017 17:53:34 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mappers/authorization/UserSettingMapper.xml | 2 ++ .../web/entity/authorization/UserSettingEntity.java | 4 ++++ .../simple/SimpleUserSettingService.java | 4 ++++ .../src/main/resources/hsweb-starter.js | 12 ++++++++++++ 4 files changed, 22 insertions(+) diff --git a/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-dao/hsweb-system-authorization-dao-mybatis/src/main/resources/org/hswebframework/web/dao/mybatis/mappers/authorization/UserSettingMapper.xml b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-dao/hsweb-system-authorization-dao-mybatis/src/main/resources/org/hswebframework/web/dao/mybatis/mappers/authorization/UserSettingMapper.xml index 5f90db0f9..011b6d6bf 100644 --- a/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-dao/hsweb-system-authorization-dao-mybatis/src/main/resources/org/hswebframework/web/dao/mybatis/mappers/authorization/UserSettingMapper.xml +++ b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-dao/hsweb-system-authorization-dao-mybatis/src/main/resources/org/hswebframework/web/dao/mybatis/mappers/authorization/UserSettingMapper.xml @@ -27,6 +27,8 @@ + + diff --git a/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-entity/src/main/java/org/hswebframework/web/entity/authorization/UserSettingEntity.java b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-entity/src/main/java/org/hswebframework/web/entity/authorization/UserSettingEntity.java index 072badbe4..5b9a1262a 100644 --- a/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-entity/src/main/java/org/hswebframework/web/entity/authorization/UserSettingEntity.java +++ b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-entity/src/main/java/org/hswebframework/web/entity/authorization/UserSettingEntity.java @@ -30,6 +30,10 @@ public class UserSettingEntity extends SimpleGenericEntity { @NotBlank(groups = CreateGroup.class) private String setting; + private String describe; + + private String name; + private Date createTime; private Date updateTime; diff --git a/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-service/hsweb-system-authorization-service-simple/src/main/java/org/hswebframework/web/service/authorization/simple/SimpleUserSettingService.java b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-service/hsweb-system-authorization-service-simple/src/main/java/org/hswebframework/web/service/authorization/simple/SimpleUserSettingService.java index cfaf79298..939e5608a 100644 --- a/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-service/hsweb-system-authorization-service-simple/src/main/java/org/hswebframework/web/service/authorization/simple/SimpleUserSettingService.java +++ b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-service/hsweb-system-authorization-service-simple/src/main/java/org/hswebframework/web/service/authorization/simple/SimpleUserSettingService.java @@ -12,6 +12,7 @@ import org.springframework.cache.annotation.Cacheable; import org.springframework.cache.annotation.Caching; import org.springframework.stereotype.Service; +import java.util.Date; import java.util.List; import java.util.Objects; @@ -63,6 +64,8 @@ public class SimpleUserSettingService extends EnableCacheGenericEntityService Date: Wed, 13 Dec 2017 17:53:50 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=96=87=E6=9C=AC?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E4=B8=8B=E8=BD=BD=E4=B9=B1=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hswebframework/web/service/GenericEntityService.java | 4 ++-- .../web/controller/file/FileController.java | 9 +++------ 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/hsweb-commons/hsweb-commons-service/hsweb-commons-service-simple/src/main/java/org/hswebframework/web/service/GenericEntityService.java b/hsweb-commons/hsweb-commons-service/hsweb-commons-service-simple/src/main/java/org/hswebframework/web/service/GenericEntityService.java index 65517310e..67269a454 100644 --- a/hsweb-commons/hsweb-commons-service/hsweb-commons-service-simple/src/main/java/org/hswebframework/web/service/GenericEntityService.java +++ b/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, PK> */ protected abstract IDGenerator getIDGenerator(); - @Override - public abstract CrudDao getDao(); +// @Override +// public abstract CrudDao getDao(); @Override public int deleteByPk(PK pk) { diff --git a/hsweb-system/hsweb-system-file/hsweb-system-file-controller/src/main/java/org/hswebframework/web/controller/file/FileController.java b/hsweb-system/hsweb-system-file/hsweb-system-file-controller/src/main/java/org/hswebframework/web/controller/file/FileController.java index c487b20cb..9e15da5d5 100644 --- a/hsweb-system/hsweb-system-file/hsweb-system-file-controller/src/main/java/org/hswebframework/web/controller/file/FileController.java +++ b/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 @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); }