瀏覽代碼

优化参数校验

zhouhao 6 年之前
父節點
當前提交
f72016ab39

+ 8 - 2
hsweb-system/hsweb-system-authorization/hsweb-system-authorization-local/src/main/java/org/hswebframework/web/service/authorization/simple/SimpleUserService.java

@@ -99,7 +99,7 @@ public class SimpleUserService extends AbstractService<UserEntity, String>
     @Override
     @Transactional(readOnly = true)
     public UserEntity selectByPk(String id) {
-        if (null == id) {
+        if (!StringUtils.hasLength(id)) {
             return null;
         }
         UserEntity userEntity = createQuery().where(UserEntity.id, id).single();
@@ -218,6 +218,9 @@ public class SimpleUserService extends AbstractService<UserEntity, String>
 
     @Override
     public boolean enable(String userId) {
+        if (!StringUtils.hasLength(userId)) {
+            return false;
+        }
         return createUpdate(getDao())
                 .set(UserEntity.status, DataStatus.STATUS_ENABLED)
                 .where(GenericEntity.id, userId)
@@ -226,6 +229,9 @@ public class SimpleUserService extends AbstractService<UserEntity, String>
 
     @Override
     public boolean disable(String userId) {
+        if (!StringUtils.hasLength(userId)) {
+            return false;
+        }
         return createUpdate(getDao())
                 .set(UserEntity.status, DataStatus.STATUS_DISABLED)
                 .where(GenericEntity.id, userId)
@@ -253,7 +259,7 @@ public class SimpleUserService extends AbstractService<UserEntity, String>
 
     @Override
     public List<RoleEntity> getUserRole(String userId) {
-        Objects.requireNonNull(userId);
+        Assert.hasLength(userId,"参数不能为空");
         List<UserRoleEntity> roleEntities = userRoleDao.selectByUserId(userId);
         if (roleEntities.isEmpty()) {
             return new ArrayList<>();