mirror of
				https://github.com/continew-org/continew-starter.git
				synced 2025-10-31 22:57:19 +08:00 
			
		
		
		
	refactor: 优化字符串模板方法 API 使用
This commit is contained in:
		| @@ -75,7 +75,7 @@ public class SpringDocAutoConfiguration implements WebMvcConfigurer { | ||||
|     @Bean | ||||
|     @ConditionalOnMissingBean | ||||
|     public OpenAPI openApi(ProjectProperties projectProperties, SpringDocExtensionProperties properties) { | ||||
|         Info info = new Info().title(String.format("%s %s", projectProperties.getName(), "API 文档")) | ||||
|         Info info = new Info().title("%s %s".formatted(projectProperties.getName(), "API 文档")) | ||||
|             .version(projectProperties.getVersion()) | ||||
|             .description(projectProperties.getDescription()); | ||||
|         ProjectProperties.Contact contact = projectProperties.getContact(); | ||||
|   | ||||
| @@ -140,7 +140,7 @@ public class SaTokenDaoRedisImpl implements SaTokenDao { | ||||
|  | ||||
|     @Override | ||||
|     public List<String> searchData(String prefix, String keyword, int start, int size, boolean sortType) { | ||||
|         Collection<String> keys = RedisUtils.keys(String.format("%s*%s*", prefix, keyword)); | ||||
|         Collection<String> keys = RedisUtils.keys("%s*%s*".formatted(prefix, keyword)); | ||||
|         List<String> list = new ArrayList<>(keys); | ||||
|         return SaFoxUtil.searchList(list, start, size, sortType); | ||||
|     } | ||||
|   | ||||
| @@ -97,7 +97,7 @@ public class SpringCacheAutoConfiguration implements CachingConfigurer { | ||||
|             for (int i = 0; i < params.length; i++) { | ||||
|                 paramMap.put(String.valueOf(i), params[i]); | ||||
|             } | ||||
|             return String.format("%s:%s", key, DigestUtil.sha256Hex(JSONUtil.toJsonStr(paramMap))); | ||||
|             return "%s:%s".formatted(key, DigestUtil.sha256Hex(JSONUtil.toJsonStr(paramMap))); | ||||
|         }; | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -62,7 +62,7 @@ public class MetaUtils { | ||||
|         List<Entity> tableEntityList; | ||||
|         Db db = Db.use(dataSource); | ||||
|         if (CharSequenceUtil.isNotBlank(tableName)) { | ||||
|             tableEntityList = db.query(String.format("%s WHERE NAME = ?", querySql), tableName); | ||||
|             tableEntityList = db.query("%s WHERE NAME = ?".formatted(querySql), tableName); | ||||
|         } else { | ||||
|             tableEntityList = db.query(querySql); | ||||
|         } | ||||
|   | ||||
| @@ -45,7 +45,7 @@ public class CheckUtils extends Validator { | ||||
|      * @param fieldValue 字段值 | ||||
|      */ | ||||
|     public static void throwIfNotExists(Object obj, String entityName, String fieldName, Object fieldValue) { | ||||
|         String message = String.format("%s 为 [%s] 的 %s 记录已不存在", fieldName, fieldValue, CharSequenceUtil | ||||
|         String message = "%s 为 [%s] 的 %s 记录已不存在".formatted(fieldName, fieldValue, CharSequenceUtil | ||||
|             .replace(entityName, "DO", StringConstants.EMPTY)); | ||||
|         throwIfNull(obj, message, EXCEPTION_TYPE); | ||||
|     } | ||||
| @@ -81,7 +81,7 @@ public class CheckUtils extends Validator { | ||||
|      * @param fieldValue 字段值 | ||||
|      */ | ||||
|     public static void throwIfExists(Object obj, String entityName, String fieldName, Object fieldValue) { | ||||
|         String message = String.format("%s 为 [%s] 的 %s 记录已存在", fieldName, fieldValue, entityName); | ||||
|         String message = "%s 为 [%s] 的 %s 记录已存在".formatted(fieldName, fieldValue, entityName); | ||||
|         throwIfNotNull(obj, message, EXCEPTION_TYPE); | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -102,7 +102,7 @@ public class DataPermissionHandlerImpl implements DataPermissionHandler { | ||||
|                 case DEPT -> expression = this.buildDeptExpression(dataPermission, currentUser, expression); | ||||
|                 case SELF -> expression = this.buildSelfExpression(dataPermission, currentUser, expression); | ||||
|                 case CUSTOM -> expression = this.buildCustomExpression(dataPermission, role, expression); | ||||
|                 default -> throw new IllegalArgumentException(String.format("暂不支持 [%s] 数据权限", dataScope)); | ||||
|                 default -> throw new IllegalArgumentException("暂不支持 [%s] 数据权限".formatted(dataScope)); | ||||
|             } | ||||
|         } | ||||
|         return null != where ? new AndExpression(where, new Parenthesis(expression)) : expression; | ||||
| @@ -227,7 +227,7 @@ public class DataPermissionHandlerImpl implements DataPermissionHandler { | ||||
|      */ | ||||
|     private Column buildColumn(String tableAlias, String columnName) { | ||||
|         if (StringUtils.isNotEmpty(tableAlias)) { | ||||
|             return new Column(String.format("%s.%s", tableAlias, columnName)); | ||||
|             return new Column("%s.%s".formatted(tableAlias, columnName)); | ||||
|         } | ||||
|         return new Column(columnName); | ||||
|     } | ||||
|   | ||||
| @@ -182,7 +182,7 @@ public class QueryWrapperHelper { | ||||
|             } | ||||
|             case IS_NULL -> consumers.add(q -> q.isNull(columnName)); | ||||
|             case IS_NOT_NULL -> consumers.add(q -> q.isNotNull(columnName)); | ||||
|             default -> throw new IllegalArgumentException(String.format("暂不支持 [%s] 查询类型", queryType)); | ||||
|             default -> throw new IllegalArgumentException("暂不支持 [%s] 查询类型".formatted(queryType)); | ||||
|         } | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -186,6 +186,6 @@ public abstract class BaseController<S extends BaseService<L, D, Q, C>, L, D, Q, | ||||
|         String path = crudRequestMapping.value(); | ||||
|         String permissionPrefix = String.join(StringConstants.COLON, CharSequenceUtil | ||||
|             .splitTrim(path, StringConstants.SLASH)); | ||||
|         StpUtil.checkPermission(String.format("%s:%s", permissionPrefix, api.name().toLowerCase())); | ||||
|         StpUtil.checkPermission("%s:%s".formatted(permissionPrefix, api.name().toLowerCase())); | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -70,7 +70,7 @@ public class ExcelUtils { | ||||
|                                   Class<T> clazz, | ||||
|                                   HttpServletResponse response) { | ||||
|         try { | ||||
|             String exportFileName = URLUtil.encode(String.format("%s_%s.xlsx", fileName, DateUtil | ||||
|             String exportFileName = URLUtil.encode("%s_%s.xlsx".formatted(fileName, DateUtil | ||||
|                 .format(new Date(), DatePattern.PURE_DATETIME_PATTERN))); | ||||
|             response.setHeader("Content-disposition", "attachment;filename=" + exportFileName); | ||||
|             response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8"); | ||||
|   | ||||
| @@ -58,11 +58,11 @@ public class LocalStorageAutoConfiguration implements WebMvcConfigurer { | ||||
|             String pathPattern = mapping.getPathPattern(); | ||||
|             String location = mapping.getLocation(); | ||||
|             if (CharSequenceUtil.isBlank(location)) { | ||||
|                 throw new IllegalArgumentException(String.format("Path pattern [%s] location is null.", pathPattern)); | ||||
|                 throw new IllegalArgumentException("Path pattern [%s] location is null.".formatted(pathPattern)); | ||||
|             } | ||||
|             registry.addResourceHandler(CharSequenceUtil.appendIfMissing(pathPattern, StringConstants.PATH_PATTERN)) | ||||
|                 .addResourceLocations(!location.startsWith("file:") | ||||
|                     ? String.format("file:%s", this.format(location)) | ||||
|                     ? "file:%s".formatted(this.format(location)) | ||||
|                     : this.format(location)) | ||||
|                 .setCachePeriod(0); | ||||
|         } | ||||
|   | ||||
| @@ -112,7 +112,7 @@ public class GlobalExceptionHandler { | ||||
|     public R<Void> handleMaxUploadSizeExceededException(MaxUploadSizeExceededException e, HttpServletRequest request) { | ||||
|         log.warn("请求地址 [{}],上传文件失败,文件大小超过限制。", request.getRequestURI(), e); | ||||
|         String sizeLimit = CharSequenceUtil.subBetween(e.getMessage(), "The maximum size ", " for"); | ||||
|         String errorMsg = String.format("请上传小于 %sMB 的文件", NumberUtil.parseLong(sizeLimit) / 1024 / 1024); | ||||
|         String errorMsg = "请上传小于 %sMB 的文件".formatted(NumberUtil.parseLong(sizeLimit) / 1024 / 1024); | ||||
|         return R.fail(HttpStatus.BAD_REQUEST.value(), errorMsg); | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -54,10 +54,10 @@ public class FileUploadUtils { | ||||
|  | ||||
|         String fileName; | ||||
|         if (isKeepOriginalFilename) { | ||||
|             fileName = String.format("%s-%s.%s", FileNameUtil.getPrefix(originalFilename), DateUtil.format(LocalDateTime | ||||
|             fileName = "%s-%s.%s".formatted(FileNameUtil.getPrefix(originalFilename), DateUtil.format(LocalDateTime | ||||
|                 .now(), DatePattern.PURE_DATETIME_MS_PATTERN), extensionName); | ||||
|         } else { | ||||
|             fileName = String.format("%s.%s", IdUtil.fastSimpleUUID(), extensionName); | ||||
|             fileName = "%s.%s".formatted(IdUtil.fastSimpleUUID(), extensionName); | ||||
|         } | ||||
|  | ||||
|         try { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user