mirror of
https://github.com/continew-org/continew-starter.git
synced 2025-10-01 14:57:13 +08:00
refactor: 优化字符串模板方法 API 使用
This commit is contained in:
@@ -75,7 +75,7 @@ public class SpringDocAutoConfiguration implements WebMvcConfigurer {
|
|||||||
@Bean
|
@Bean
|
||||||
@ConditionalOnMissingBean
|
@ConditionalOnMissingBean
|
||||||
public OpenAPI openApi(ProjectProperties projectProperties, SpringDocExtensionProperties properties) {
|
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())
|
.version(projectProperties.getVersion())
|
||||||
.description(projectProperties.getDescription());
|
.description(projectProperties.getDescription());
|
||||||
ProjectProperties.Contact contact = projectProperties.getContact();
|
ProjectProperties.Contact contact = projectProperties.getContact();
|
||||||
|
@@ -140,7 +140,7 @@ public class SaTokenDaoRedisImpl implements SaTokenDao {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> searchData(String prefix, String keyword, int start, int size, boolean sortType) {
|
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);
|
List<String> list = new ArrayList<>(keys);
|
||||||
return SaFoxUtil.searchList(list, start, size, sortType);
|
return SaFoxUtil.searchList(list, start, size, sortType);
|
||||||
}
|
}
|
||||||
|
@@ -97,7 +97,7 @@ public class SpringCacheAutoConfiguration implements CachingConfigurer {
|
|||||||
for (int i = 0; i < params.length; i++) {
|
for (int i = 0; i < params.length; i++) {
|
||||||
paramMap.put(String.valueOf(i), params[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;
|
List<Entity> tableEntityList;
|
||||||
Db db = Db.use(dataSource);
|
Db db = Db.use(dataSource);
|
||||||
if (CharSequenceUtil.isNotBlank(tableName)) {
|
if (CharSequenceUtil.isNotBlank(tableName)) {
|
||||||
tableEntityList = db.query(String.format("%s WHERE NAME = ?", querySql), tableName);
|
tableEntityList = db.query("%s WHERE NAME = ?".formatted(querySql), tableName);
|
||||||
} else {
|
} else {
|
||||||
tableEntityList = db.query(querySql);
|
tableEntityList = db.query(querySql);
|
||||||
}
|
}
|
||||||
|
@@ -45,7 +45,7 @@ public class CheckUtils extends Validator {
|
|||||||
* @param fieldValue 字段值
|
* @param fieldValue 字段值
|
||||||
*/
|
*/
|
||||||
public static void throwIfNotExists(Object obj, String entityName, String fieldName, Object 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));
|
.replace(entityName, "DO", StringConstants.EMPTY));
|
||||||
throwIfNull(obj, message, EXCEPTION_TYPE);
|
throwIfNull(obj, message, EXCEPTION_TYPE);
|
||||||
}
|
}
|
||||||
@@ -81,7 +81,7 @@ public class CheckUtils extends Validator {
|
|||||||
* @param fieldValue 字段值
|
* @param fieldValue 字段值
|
||||||
*/
|
*/
|
||||||
public static void throwIfExists(Object obj, String entityName, String fieldName, Object 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);
|
throwIfNotNull(obj, message, EXCEPTION_TYPE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -102,7 +102,7 @@ public class DataPermissionHandlerImpl implements DataPermissionHandler {
|
|||||||
case DEPT -> expression = this.buildDeptExpression(dataPermission, currentUser, expression);
|
case DEPT -> expression = this.buildDeptExpression(dataPermission, currentUser, expression);
|
||||||
case SELF -> expression = this.buildSelfExpression(dataPermission, currentUser, expression);
|
case SELF -> expression = this.buildSelfExpression(dataPermission, currentUser, expression);
|
||||||
case CUSTOM -> expression = this.buildCustomExpression(dataPermission, role, 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;
|
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) {
|
private Column buildColumn(String tableAlias, String columnName) {
|
||||||
if (StringUtils.isNotEmpty(tableAlias)) {
|
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);
|
return new Column(columnName);
|
||||||
}
|
}
|
||||||
|
@@ -182,7 +182,7 @@ public class QueryWrapperHelper {
|
|||||||
}
|
}
|
||||||
case IS_NULL -> consumers.add(q -> q.isNull(columnName));
|
case IS_NULL -> consumers.add(q -> q.isNull(columnName));
|
||||||
case IS_NOT_NULL -> consumers.add(q -> q.isNotNull(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 path = crudRequestMapping.value();
|
||||||
String permissionPrefix = String.join(StringConstants.COLON, CharSequenceUtil
|
String permissionPrefix = String.join(StringConstants.COLON, CharSequenceUtil
|
||||||
.splitTrim(path, StringConstants.SLASH));
|
.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,
|
Class<T> clazz,
|
||||||
HttpServletResponse response) {
|
HttpServletResponse response) {
|
||||||
try {
|
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)));
|
.format(new Date(), DatePattern.PURE_DATETIME_PATTERN)));
|
||||||
response.setHeader("Content-disposition", "attachment;filename=" + exportFileName);
|
response.setHeader("Content-disposition", "attachment;filename=" + exportFileName);
|
||||||
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8");
|
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 pathPattern = mapping.getPathPattern();
|
||||||
String location = mapping.getLocation();
|
String location = mapping.getLocation();
|
||||||
if (CharSequenceUtil.isBlank(location)) {
|
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))
|
registry.addResourceHandler(CharSequenceUtil.appendIfMissing(pathPattern, StringConstants.PATH_PATTERN))
|
||||||
.addResourceLocations(!location.startsWith("file:")
|
.addResourceLocations(!location.startsWith("file:")
|
||||||
? String.format("file:%s", this.format(location))
|
? "file:%s".formatted(this.format(location))
|
||||||
: this.format(location))
|
: this.format(location))
|
||||||
.setCachePeriod(0);
|
.setCachePeriod(0);
|
||||||
}
|
}
|
||||||
|
@@ -112,7 +112,7 @@ public class GlobalExceptionHandler {
|
|||||||
public R<Void> handleMaxUploadSizeExceededException(MaxUploadSizeExceededException e, HttpServletRequest request) {
|
public R<Void> handleMaxUploadSizeExceededException(MaxUploadSizeExceededException e, HttpServletRequest request) {
|
||||||
log.warn("请求地址 [{}],上传文件失败,文件大小超过限制。", request.getRequestURI(), e);
|
log.warn("请求地址 [{}],上传文件失败,文件大小超过限制。", request.getRequestURI(), e);
|
||||||
String sizeLimit = CharSequenceUtil.subBetween(e.getMessage(), "The maximum size ", " for");
|
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);
|
return R.fail(HttpStatus.BAD_REQUEST.value(), errorMsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -54,10 +54,10 @@ public class FileUploadUtils {
|
|||||||
|
|
||||||
String fileName;
|
String fileName;
|
||||||
if (isKeepOriginalFilename) {
|
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);
|
.now(), DatePattern.PURE_DATETIME_MS_PATTERN), extensionName);
|
||||||
} else {
|
} else {
|
||||||
fileName = String.format("%s.%s", IdUtil.fastSimpleUUID(), extensionName);
|
fileName = "%s.%s".formatted(IdUtil.fastSimpleUUID(), extensionName);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
Reference in New Issue
Block a user