mirror of
https://github.com/continew-org/continew-starter.git
synced 2025-09-09 08:57:17 +08:00
style: 优化全局代码格式
This commit is contained in:
@@ -81,8 +81,9 @@ public class ProjectProperties {
|
||||
public static final boolean IP_ADDR_LOCAL_PARSE_ENABLED;
|
||||
|
||||
static {
|
||||
IP_ADDR_LOCAL_PARSE_ENABLED = SpringUtil.getProperty("project.ip-addr-local-parse-enabled", boolean.class, false)
|
||||
|| SpringUtil.getProperty("project.ipAddrLocalParseEnabled", boolean.class, false);
|
||||
IP_ADDR_LOCAL_PARSE_ENABLED = SpringUtil
|
||||
.getProperty("project.ip-addr-local-parse-enabled", boolean.class, false) || SpringUtil
|
||||
.getProperty("project.ipAddrLocalParseEnabled", boolean.class, false);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -66,8 +66,10 @@ public class AsyncAutoConfiguration implements AsyncConfigurer {
|
||||
return (throwable, method, objects) -> {
|
||||
throwable.printStackTrace();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("Exception message: ").append(throwable.getMessage()).append(", Method name: ")
|
||||
.append(method.getName());
|
||||
sb.append("Exception message: ")
|
||||
.append(throwable.getMessage())
|
||||
.append(", Method name: ")
|
||||
.append(method.getName());
|
||||
if (ArrayUtil.isNotEmpty(objects)) {
|
||||
sb.append(", Parameter value: ").append(Arrays.toString(objects));
|
||||
}
|
||||
|
@@ -78,9 +78,9 @@ public class ThreadPoolAutoConfiguration {
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public ScheduledExecutorService scheduledExecutorService(ThreadPoolProperties properties) {
|
||||
ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(ObjectUtil.defaultIfNull(properties.getCorePoolSize(), corePoolSize),
|
||||
ThreadUtil.newNamedThreadFactory("schedule-pool-%d", true),
|
||||
new ThreadPoolExecutor.CallerRunsPolicy()) {
|
||||
ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(ObjectUtil.defaultIfNull(properties
|
||||
.getCorePoolSize(), corePoolSize), ThreadUtil
|
||||
.newNamedThreadFactory("schedule-pool-%d", true), new ThreadPoolExecutor.CallerRunsPolicy()) {
|
||||
@Override
|
||||
protected void afterExecute(Runnable runnable, Throwable throwable) {
|
||||
super.afterExecute(runnable, throwable);
|
||||
|
@@ -27,7 +27,11 @@ import org.springframework.lang.Nullable;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* 通用配置文件读取工厂(DefaultPropertySourceFactory 仅支持 properties 配置文件读取,详见:<a href="https://docs.spring.io/spring-boot/docs/2.0.6.RELEASE/reference/html/boot-features-external-config.html#boot-features-external-config-yaml-shortcomings">YAML Shortcomings</a>)
|
||||
* 通用配置文件读取工厂
|
||||
* <p>
|
||||
* DefaultPropertySourceFactory 仅支持 properties
|
||||
* 配置文件读取,详见:<ahref="https://docs.spring.io/spring-boot/docs/2.0.6.RELEASE/reference/html/boot-features-external-config.html#boot-features-external-config-yaml-shortcomings">YAMLShortcomings</a>
|
||||
* </p>
|
||||
*
|
||||
* @author Charles7c
|
||||
* @since 1.0.0
|
||||
@@ -35,7 +39,8 @@ import java.io.IOException;
|
||||
public class GeneralPropertySourceFactory extends DefaultPropertySourceFactory {
|
||||
|
||||
@Override
|
||||
public PropertySource<?> createPropertySource(@Nullable String name, EncodedResource encodedResource) throws IOException {
|
||||
public PropertySource<?> createPropertySource(@Nullable String name,
|
||||
EncodedResource encodedResource) throws IOException {
|
||||
Resource resource = encodedResource.getResource();
|
||||
String resourceName = resource.getFilename();
|
||||
if (StrUtil.isNotBlank(resourceName) && StrUtil.endWithAny(resourceName, ".yml", ".yaml")) {
|
||||
|
@@ -53,8 +53,8 @@ public class FileUploadUtils {
|
||||
|
||||
String fileName;
|
||||
if (isKeepOriginalFilename) {
|
||||
fileName = String.format("%s-%s.%s", FileNameUtil.getPrefix(originalFilename),
|
||||
DateUtil.format(LocalDateTime.now(), DatePattern.PURE_DATETIME_MS_PATTERN), extensionName);
|
||||
fileName = String.format("%s-%s.%s", FileNameUtil.getPrefix(originalFilename), DateUtil.format(LocalDateTime
|
||||
.now(), DatePattern.PURE_DATETIME_MS_PATTERN), extensionName);
|
||||
} else {
|
||||
fileName = String.format("%s.%s", IdUtil.fastSimpleUUID(), extensionName);
|
||||
}
|
||||
|
@@ -120,6 +120,6 @@ public class ServletUtils {
|
||||
}
|
||||
|
||||
private static ServletRequestAttributes getServletRequestAttributes() {
|
||||
return (ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes());
|
||||
return (ServletRequestAttributes)Objects.requireNonNull(RequestContextHolder.getRequestAttributes());
|
||||
}
|
||||
}
|
||||
|
@@ -49,8 +49,10 @@ public class SpringUtils {
|
||||
public static void deRegisterResourceHandler(Map<String, String> handlerMap) {
|
||||
ApplicationContext applicationContext = SpringUtil.getApplicationContext();
|
||||
// 获取已经注册的映射
|
||||
final HandlerMapping resourceHandlerMapping = applicationContext.getBean("resourceHandlerMapping", HandlerMapping.class);
|
||||
final Map<String, Object> oldHandlerMap = (Map<String, Object>) ReflectUtil.getFieldValue(resourceHandlerMapping, "handlerMap");
|
||||
final HandlerMapping resourceHandlerMapping = applicationContext
|
||||
.getBean("resourceHandlerMapping", HandlerMapping.class);
|
||||
final Map<String, Object> oldHandlerMap = (Map<String, Object>)ReflectUtil
|
||||
.getFieldValue(resourceHandlerMapping, "handlerMap");
|
||||
// 移除之前注册的映射
|
||||
for (Map.Entry<String, String> entry : handlerMap.entrySet()) {
|
||||
String pathPattern = StrUtil.appendIfMissing(entry.getKey(), StringConstants.PATH_PATTERN);
|
||||
@@ -66,11 +68,14 @@ public class SpringUtils {
|
||||
public static void registerResourceHandler(Map<String, String> handlerMap) {
|
||||
ApplicationContext applicationContext = SpringUtil.getApplicationContext();
|
||||
// 获取已经注册的映射
|
||||
final HandlerMapping resourceHandlerMapping = applicationContext.getBean("resourceHandlerMapping", HandlerMapping.class);
|
||||
final Map<String, Object> oldHandlerMap = (Map<String, Object>) ReflectUtil.getFieldValue(resourceHandlerMapping, "handlerMap");
|
||||
final HandlerMapping resourceHandlerMapping = applicationContext
|
||||
.getBean("resourceHandlerMapping", HandlerMapping.class);
|
||||
final Map<String, Object> oldHandlerMap = (Map<String, Object>)ReflectUtil
|
||||
.getFieldValue(resourceHandlerMapping, "handlerMap");
|
||||
// 重新注册映射
|
||||
final ServletContext servletContext = applicationContext.getBean(ServletContext.class);
|
||||
final ContentNegotiationManager contentNegotiationManager = applicationContext.getBean("mvcContentNegotiationManager", ContentNegotiationManager.class);
|
||||
final ContentNegotiationManager contentNegotiationManager = applicationContext
|
||||
.getBean("mvcContentNegotiationManager", ContentNegotiationManager.class);
|
||||
final UrlPathHelper urlPathHelper = applicationContext.getBean("mvcUrlPathHelper", UrlPathHelper.class);
|
||||
final ResourceHandlerRegistry resourceHandlerRegistry = new ResourceHandlerRegistry(applicationContext, servletContext, contentNegotiationManager, urlPathHelper);
|
||||
for (Map.Entry<String, String> entry : handlerMap.entrySet()) {
|
||||
@@ -81,7 +86,9 @@ public class SpringUtils {
|
||||
String resourceLocations = StrUtil.appendIfMissing(entry.getValue(), StringConstants.SLASH);
|
||||
resourceHandlerRegistry.addResourceHandler(pathPattern).addResourceLocations("file:" + resourceLocations);
|
||||
}
|
||||
final Map<String, ?> additionalUrlMap = ReflectUtil.<SimpleUrlHandlerMapping>invoke(resourceHandlerRegistry, "getHandlerMapping").getUrlMap();
|
||||
final Map<String, ?> additionalUrlMap = ReflectUtil
|
||||
.<SimpleUrlHandlerMapping>invoke(resourceHandlerRegistry, "getHandlerMapping")
|
||||
.getUrlMap();
|
||||
ReflectUtil.<Void>invoke(resourceHandlerMapping, "registerHandlers", additionalUrlMap);
|
||||
}
|
||||
}
|
||||
|
@@ -56,8 +56,8 @@ public class TemplateUtils {
|
||||
* @return 渲染后的内容
|
||||
*/
|
||||
public static String render(String parentPath, String templatePath, Map<?, ?> bindingMap) {
|
||||
TemplateEngine engine =
|
||||
TemplateUtil.createEngine(new TemplateConfig(parentPath, TemplateConfig.ResourceMode.CLASSPATH));
|
||||
TemplateEngine engine = TemplateUtil
|
||||
.createEngine(new TemplateConfig(parentPath, TemplateConfig.ResourceMode.CLASSPATH));
|
||||
Template template = engine.getTemplate(templatePath);
|
||||
return template.render(bindingMap);
|
||||
}
|
||||
|
@@ -47,8 +47,8 @@ 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,
|
||||
StrUtil.replace(entityName, "DO", StringConstants.EMPTY));
|
||||
String message = String.format("%s 为 [%s] 的 %s 记录已不存在", fieldName, fieldValue, StrUtil
|
||||
.replace(entityName, "DO", StringConstants.EMPTY));
|
||||
throwIfNull(obj, message, EXCEPTION_TYPE);
|
||||
}
|
||||
|
||||
@@ -175,7 +175,9 @@ public class CheckUtils extends Validator {
|
||||
* @param template 异常信息模板,被替换的部分用 {} 表示,如果模板为 null,返回 "null"
|
||||
* @param params 参数值
|
||||
*/
|
||||
public static void throwIfNotEqualIgnoreCase(CharSequence str1, CharSequence str2, String template,
|
||||
public static void throwIfNotEqualIgnoreCase(CharSequence str1,
|
||||
CharSequence str2,
|
||||
String template,
|
||||
Object... params) {
|
||||
throwIfNotEqualIgnoreCase(str1, str2, StrUtil.format(template, params), EXCEPTION_TYPE);
|
||||
}
|
||||
|
@@ -147,7 +147,9 @@ public class ValidationUtils extends Validator {
|
||||
* @param template 异常信息模板,被替换的部分用 {} 表示,如果模板为 null,返回 "null"
|
||||
* @param params 参数值
|
||||
*/
|
||||
public static void throwIfNotEqualIgnoreCase(CharSequence str1, CharSequence str2, String template,
|
||||
public static void throwIfNotEqualIgnoreCase(CharSequence str1,
|
||||
CharSequence str2,
|
||||
String template,
|
||||
Object... params) {
|
||||
throwIfNotEqualIgnoreCase(str1, str2, StrUtil.format(template, params), EXCEPTION_TYPE);
|
||||
}
|
||||
|
@@ -86,7 +86,8 @@ public class Validator {
|
||||
* @param message 错误信息
|
||||
* @param exceptionType 异常类型
|
||||
*/
|
||||
protected static void throwIfBlank(CharSequence str, String message,
|
||||
protected static void throwIfBlank(CharSequence str,
|
||||
String message,
|
||||
Class<? extends RuntimeException> exceptionType) {
|
||||
throwIf(StrUtil.isBlank(str), message, exceptionType);
|
||||
}
|
||||
@@ -98,7 +99,8 @@ public class Validator {
|
||||
* @param message 错误信息
|
||||
* @param exceptionType 异常类型
|
||||
*/
|
||||
protected static void throwIfNotBlank(CharSequence str, String message,
|
||||
protected static void throwIfNotBlank(CharSequence str,
|
||||
String message,
|
||||
Class<? extends RuntimeException> exceptionType) {
|
||||
throwIf(StrUtil.isNotBlank(str), message, exceptionType);
|
||||
}
|
||||
@@ -111,7 +113,9 @@ public class Validator {
|
||||
* @param message 错误信息
|
||||
* @param exceptionType 异常类型
|
||||
*/
|
||||
protected static void throwIfEqual(Object obj1, Object obj2, String message,
|
||||
protected static void throwIfEqual(Object obj1,
|
||||
Object obj2,
|
||||
String message,
|
||||
Class<? extends RuntimeException> exceptionType) {
|
||||
throwIf(ObjectUtil.equal(obj1, obj2), message, exceptionType);
|
||||
}
|
||||
@@ -124,7 +128,9 @@ public class Validator {
|
||||
* @param message 错误信息
|
||||
* @param exceptionType 异常类型
|
||||
*/
|
||||
protected static void throwIfNotEqual(Object obj1, Object obj2, String message,
|
||||
protected static void throwIfNotEqual(Object obj1,
|
||||
Object obj2,
|
||||
String message,
|
||||
Class<? extends RuntimeException> exceptionType) {
|
||||
throwIf(ObjectUtil.notEqual(obj1, obj2), message, exceptionType);
|
||||
}
|
||||
@@ -137,7 +143,9 @@ public class Validator {
|
||||
* @param message 错误信息
|
||||
* @param exceptionType 异常类型
|
||||
*/
|
||||
protected static void throwIfEqualIgnoreCase(CharSequence str1, CharSequence str2, String message,
|
||||
protected static void throwIfEqualIgnoreCase(CharSequence str1,
|
||||
CharSequence str2,
|
||||
String message,
|
||||
Class<? extends RuntimeException> exceptionType) {
|
||||
throwIf(StrUtil.equalsIgnoreCase(str1, str2), message, exceptionType);
|
||||
}
|
||||
@@ -150,7 +158,9 @@ public class Validator {
|
||||
* @param message 错误信息
|
||||
* @param exceptionType 异常类型
|
||||
*/
|
||||
protected static void throwIfNotEqualIgnoreCase(CharSequence str1, CharSequence str2, String message,
|
||||
protected static void throwIfNotEqualIgnoreCase(CharSequence str1,
|
||||
CharSequence str2,
|
||||
String message,
|
||||
Class<? extends RuntimeException> exceptionType) {
|
||||
throwIf(!StrUtil.equalsIgnoreCase(str1, str2), message, exceptionType);
|
||||
}
|
||||
@@ -176,7 +186,8 @@ public class Validator {
|
||||
* @param message 错误信息
|
||||
* @param exceptionType 异常类型
|
||||
*/
|
||||
protected static void throwIf(BooleanSupplier conditionSupplier, String message,
|
||||
protected static void throwIf(BooleanSupplier conditionSupplier,
|
||||
String message,
|
||||
Class<? extends RuntimeException> exceptionType) {
|
||||
if (null != conditionSupplier && conditionSupplier.getAsBoolean()) {
|
||||
log.error(message);
|
||||
|
Reference in New Issue
Block a user