代码判断优化

This commit is contained in:
lhd
2024-10-10 11:08:31 +08:00
parent 10d16c1b80
commit 2da344e8e5
2 changed files with 4 additions and 4 deletions

View File

@@ -72,7 +72,7 @@ public class CategoryController {
category.setRecTime(new Date());
Category categoryName = categoryService.getOne(new LambdaQueryWrapper<Category>().eq(Category::getCategoryName,category.getCategoryName())
.eq(Category::getShopId,category.getShopId()));
if(categoryName != null){
if(Objects.nonNull(categoryName)){
throw new YamiShopBindException("类目名称已存在!");
}
categoryService.saveCategory(category);

View File

@@ -45,7 +45,7 @@ public class UserController {
.like(StrUtil.isNotBlank(user.getNickName()), User::getNickName, user.getNickName())
.eq(user.getStatus() != null, User::getStatus, user.getStatus()));
for (User userResult : userPage.getRecords()) {
userResult.setNickName(userResult.getNickName() == null ? "" : userResult.getNickName());
userResult.setNickName(StrUtil.isBlank(userResult.getNickName()) ? "" : userResult.getNickName());
}
return ServerResponseEntity.success(userPage);
}
@@ -57,7 +57,7 @@ public class UserController {
@PreAuthorize("@pms.hasPermission('admin:user:info')")
public ServerResponseEntity<User> info(@PathVariable("userId") String userId) {
User user = userService.getById(userId);
user.setNickName(user.getNickName() == null ? "" : user.getNickName());
user.setNickName(StrUtil.isBlank(user.getNickName()) ? "" : user.getNickName());
return ServerResponseEntity.success(user);
}
@@ -68,7 +68,7 @@ public class UserController {
@PreAuthorize("@pms.hasPermission('admin:user:update')")
public ServerResponseEntity<Void> update(@RequestBody User user) {
user.setModifyTime(new Date());
user.setNickName(user.getNickName() == null ? "" : user.getNickName());
user.setNickName(StrUtil.isBlank(user.getNickName()) ? "" : user.getNickName());
userService.updateById(user);
return ServerResponseEntity.success();
}