refactor: 使用 Hutool工具类优化空值判断- 在多个控制器和服务实现类中,将原始的空值判断替换为 Hutool 工具类中的方法

- 使用 ObjectUtil.isNull() 替换原始的 == null 判断
- 使用 ObjectUtil.isNotNull() 替换原始的 != null 判断
- 在某些情况下,使用 StrUtil.isBlank() 替换原始的 == null 判断,以更准确地检查字符串是否为空
This commit is contained in:
ikmkj
2025-08-02 19:53:47 +08:00
parent f858a9bcd6
commit 81678da683
10 changed files with 27 additions and 17 deletions

View File

@@ -1,6 +1,7 @@
package com.test.bijihoudaun.controller;
import cn.hutool.core.util.StrUtil;
import com.test.bijihoudaun.common.response.R;
import com.test.bijihoudaun.entity.Image;
import com.test.bijihoudaun.service.ImageService;
@@ -63,7 +64,7 @@ public class ImageController {
@GetMapping("/preview/{url}")
@Operation(summary = "在线预览", description = "浏览器直接打开文件流")
public void preview(@PathVariable String url, HttpServletResponse resp) throws IOException {
if (url == null) {
if (StrUtil.isBlank(url)) {
resp.setStatus(404);
R.fail("文件不存在");
}
@@ -113,7 +114,7 @@ public class ImageController {
* @return 对应的MIME类型
*/
private String getContentTypeFromFileExtension(String fileName) {
if (fileName == null || fileName.lastIndexOf('.') == -1) {
if (StrUtil.isBlank(fileName) || !StrUtil.contains(fileName, '.')) {
return "application/octet-stream";
}