Merge remote-tracking branch 'origin/develop' into wh/expression_utils

# Conflicts:
#	pom.xml
#	spring-boot-nebula-dependencies/pom.xml
#	spring-boot-nebula-web-common/src/main/java/com/nebula/web/common/utils/ExpressionUtil.java
This commit is contained in:
weihu 2024-06-01 22:19:49 +08:00
commit 3349fa1a44
89 changed files with 3203 additions and 1883 deletions

View File

@ -4,9 +4,11 @@ on:
push: push:
branches: branches:
- master - master
- develop
pull_request: pull_request:
branches: branches:
- master - master
- develop
jobs: jobs:
junit: junit:

View File

@ -0,0 +1,17 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

View File

@ -0,0 +1,51 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!--
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-->
<profiles version="13">
<profile kind="CodeFormatterProfile" name="'ShardingSphere Apache Current'" version="13">
<setting id="org.eclipse.jdt.core.compiler.source" value="1.8" />
<setting id="org.eclipse.jdt.core.compiler.compliance" value="1.8" />
<setting id="org.eclipse.jdt.core.compiler.codegen.targetPlatform" value="1.8" />
<setting id="org.eclipse.jdt.core.formatter.indent_empty_lines" value="true" />
<setting id="org.eclipse.jdt.core.formatter.tabulation.size" value="4" />
<setting id="org.eclipse.jdt.core.formatter.lineSplit" value="200" />
<setting id="org.eclipse.jdt.core.formatter.comment.line_length" value="200" />
<setting id="org.eclipse.jdt.core.formatter.tabulation.char" value="space" />
<setting id="org.eclipse.jdt.core.formatter.indentation.size" value="1" />
<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_first_class_body_declaration" value="1" />
<setting id="org.eclipse.jdt.core.formatter.comment.format_javadoc_comments" value="false" />
<setting id="org.eclipse.jdt.core.formatter.join_wrapped_lines" value="false" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_conditional" value="insert" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_default" value="do not insert" />
<setting id="org.eclipse.jdt.core.formatter.alignment_for_enum_constants" value="16" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_labeled_statement" value="do not insert" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_case" value="do not insert" />
<setting id="org.eclipse.jdt.core.formatter.alignment_for_conditional_expression" value="80" />
<setting id="org.eclipse.jdt.core.formatter.alignment_for_assignment" value="16" />
<setting id="org.eclipse.jdt.core.formatter.blank_lines_after_package" value="1" />
<setting id="org.eclipse.jdt.core.formatter.continuation_indentation_for_array_initializer" value="2" />
<setting id="org.eclipse.jdt.core.formatter.alignment_for_resources_in_try" value="160" />
<setting id="org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_method_declaration" value="10" />
<setting id="org.eclipse.jdt.core.formatter.alignment_for_parameters_in_method_declaration" value="106" />
<setting id="org.eclipse.jdt.core.formatter.alignment_for_parameters_in_constructor_declaration" value="106" />
<setting id="org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_constructor_declaration" value="106" />
<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_explicit_constructor_call.count_dependent" value="16|5|80" />
</profile>
</profiles>

139
pom.xml
View File

@ -1,13 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>io.github.weihubeats</groupId> <groupId>io.github.weihubeats</groupId>
<artifactId>spring-boot-nebula</artifactId> <artifactId>spring-boot-nebula</artifactId>
<packaging>pom</packaging>
<version>${revision}</version> <version>${revision}</version>
<packaging>pom</packaging>
<name>spring-boot-nebula</name>
<description>spring-boot-common</description>
<modules> <modules>
<module>spring-boot-nebula-web</module> <module>spring-boot-nebula-web</module>
@ -22,29 +24,15 @@
<module>spring-boot-nebula-all</module> <module>spring-boot-nebula-all</module>
</modules> </modules>
<name>spring-boot-nebula</name>
<description>spring-boot-common</description>
<url>https://github.com/weihubeats/spring-boot-common</url>
<properties> <properties>
<revision>0.0.01</revision> <revision>0.0.01</revision>
<flatten-maven-plugin.version>1.2.7</flatten-maven-plugin.version> <flatten-maven-plugin.version>1.2.7</flatten-maven-plugin.version>
<maven-gpg-plugin.version>3.0.1</maven-gpg-plugin.version> <maven-gpg-plugin.version>3.0.1</maven-gpg-plugin.version>
<maven.compiler.source>11</maven.compiler.source> <maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target> <maven.compiler.target>11</maven.compiler.target>
<spotless-maven-plugin.version>2.43.0</spotless-maven-plugin.version>
</properties> </properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement> <dependencyManagement>
<dependencies> <dependencies>
<dependency> <dependency>
@ -57,35 +45,6 @@
</dependencies> </dependencies>
</dependencyManagement> </dependencyManagement>
<licenses>
<license>
<name>The Apache Software License, Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
<distribution>repo</distribution>
</license>
</licenses>
<developers>
<developer>
<name>weihubeats</name>
<email>weihu@apche.org</email>
<organization>https://weihubeats.blog.csdn.net/</organization>
</developer>
</developers>
<scm>
<connection>scm:git@github.com:weihubeats/spring-boot-common.git</connection>
<developerConnection>scm:git@github.com:weihubeats/spring-boot-common.git</developerConnection>
<url>git@github.com:weihubeats/spring-boot-common.git</url>
</scm>
<issueManagement>
<system>Github Issue</system>
<url>https://github.com/weihubeats/spring-boot-common/issues</url>
</issueManagement>
<build> <build>
<plugins> <plugins>
<plugin> <plugin>
@ -118,10 +77,10 @@
</configuration> </configuration>
<executions> <executions>
<execution> <execution>
<phase>package</phase>
<goals> <goals>
<goal>jar-no-fork</goal> <goal>jar-no-fork</goal>
</goals> </goals>
<phase>package</phase>
</execution> </execution>
</executions> </executions>
</plugin> </plugin>
@ -143,10 +102,10 @@
</configuration> </configuration>
<executions> <executions>
<execution> <execution>
<phase>package</phase>
<goals> <goals>
<goal>jar</goal> <goal>jar</goal>
</goals> </goals>
<phase>package</phase>
</execution> </execution>
</executions> </executions>
</plugin> </plugin>
@ -158,10 +117,10 @@
<executions> <executions>
<execution> <execution>
<id>sign-artifacts</id> <id>sign-artifacts</id>
<phase>verify</phase>
<goals> <goals>
<goal>sign</goal> <goal>sign</goal>
</goals> </goals>
<phase>verify</phase>
</execution> </execution>
</executions> </executions>
</plugin> </plugin>
@ -177,32 +136,100 @@
<executions> <executions>
<execution> <execution>
<id>flatten</id> <id>flatten</id>
<phase>process-resources</phase>
<goals> <goals>
<goal>flatten</goal> <goal>flatten</goal>
</goals> </goals>
<phase>process-resources</phase>
</execution> </execution>
<execution> <execution>
<id>flatten.clean</id> <id>flatten.clean</id>
<phase>clean</phase>
<goals> <goals>
<goal>clean</goal> <goal>clean</goal>
</goals> </goals>
<phase>clean</phase>
</execution> </execution>
</executions> </executions>
</plugin> </plugin>
<plugin>
<groupId>com.diffplug.spotless</groupId>
<artifactId>spotless-maven-plugin</artifactId>
<version>${spotless-maven-plugin.version}</version>
<configuration>
<java>
<eclipse>
<file>${maven.multiModuleProjectDirectory}/dev-support/spotless_nebula_formatter.xml</file>
</eclipse>
<licenseHeader>
<file>${maven.multiModuleProjectDirectory}/dev-support/license-header</file>
</licenseHeader>
</java>
<pom>
<sortPom>
<encoding>UTF-8</encoding>
<nrOfIndentSpace>4</nrOfIndentSpace>
<keepBlankLines>true</keepBlankLines>
<indentBlankLines>false</indentBlankLines>
<indentSchemaLocation>true</indentSchemaLocation>
<spaceBeforeCloseEmptyElement>true</spaceBeforeCloseEmptyElement>
<sortModules>false</sortModules>
<sortExecutions>false</sortExecutions>
<predefinedSortOrder>custom_1</predefinedSortOrder>
<expandEmptyElements>false</expandEmptyElements>
<sortProperties>false</sortProperties>
</sortPom>
</pom>
</configuration>
<executions>
<execution>
<goals>
<goal>apply</goal>
</goals>
<phase>compile</phase>
</execution>
</executions>
</plugin>
</plugins> </plugins>
</build> </build>
<url>https://github.com/weihubeats/spring-boot-common</url>
<licenses>
<license>
<name>The Apache Software License, Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
<distribution>repo</distribution>
</license>
</licenses>
<developers>
<developer>
<name>weihubeats</name>
<email>weihu@apche.org</email>
<organization>https://weihubeats.blog.csdn.net/</organization>
</developer>
</developers>
<scm>
<connection>scm:git@github.com:weihubeats/spring-boot-common.git</connection>
<developerConnection>scm:git@github.com:weihubeats/spring-boot-common.git</developerConnection>
<url>git@github.com:weihubeats/spring-boot-common.git</url>
</scm>
<issueManagement>
<system>Github Issue</system>
<url>https://github.com/weihubeats/spring-boot-common/issues</url>
</issueManagement>
<distributionManagement> <distributionManagement>
<snapshotRepository>
<id>sonatype</id>
<url>https://s01.oss.sonatype.org/content/repositories/snapshots/</url>
</snapshotRepository>
<repository> <repository>
<id>sonatype</id> <id>sonatype</id>
<url>https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/</url> <url>https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</repository> </repository>
<snapshotRepository>
<id>sonatype</id>
<url>https://s01.oss.sonatype.org/content/repositories/snapshots/</url>
</snapshotRepository>
</distributionManagement> </distributionManagement>
</project> </project>

View File

@ -1,6 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<parent> <parent>
@ -11,7 +10,6 @@
<artifactId>spring-boot-nebula-aggregate</artifactId> <artifactId>spring-boot-nebula-aggregate</artifactId>
<dependencies> <dependencies>
<dependency> <dependency>

View File

@ -1,3 +1,20 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.nebula.aggregate.annotation; package com.nebula.aggregate.annotation;
import java.lang.annotation.Documented; import java.lang.annotation.Documented;

View File

@ -1,3 +1,20 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.nebula.aggregate.annotation; package com.nebula.aggregate.annotation;
import java.lang.annotation.Documented; import java.lang.annotation.Documented;

View File

@ -1,3 +1,20 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.nebula.aggregate.annotation; package com.nebula.aggregate.annotation;
import com.nebula.aggregate.core.AbstractOldObj; import com.nebula.aggregate.core.AbstractOldObj;
@ -19,7 +36,7 @@ import org.springframework.stereotype.Component;
public class CreateOldObjAspect { public class CreateOldObjAspect {
@AfterReturning(pointcut = "@annotation(com.nebula.aggregate.annotation.AggregateCreate) || " + @AfterReturning(pointcut = "@annotation(com.nebula.aggregate.annotation.AggregateCreate) || " +
"@annotation(com.nebula.aggregate.annotation.CreateOldObj)", returning = "returnVal") "@annotation(com.nebula.aggregate.annotation.CreateOldObj)", returning = "returnVal")
public void handleRequestMethod(JoinPoint pjp, Object returnVal) { public void handleRequestMethod(JoinPoint pjp, Object returnVal) {
if (returnVal instanceof AbstractOldObj) { if (returnVal instanceof AbstractOldObj) {
((AbstractOldObj) returnVal).setOldObject(copy(returnVal)); ((AbstractOldObj) returnVal).setOldObject(copy(returnVal));

View File

@ -1,3 +1,20 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.nebula.aggregate.core; package com.nebula.aggregate.core;
/** /**
@ -7,4 +24,3 @@ package com.nebula.aggregate.core;
*/ */
public abstract class AbstractAggregate<T> extends AbstractOldObj<T> { public abstract class AbstractAggregate<T> extends AbstractOldObj<T> {
} }

View File

@ -1,3 +1,20 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.nebula.aggregate.core; package com.nebula.aggregate.core;
import org.javers.core.metamodel.annotation.DiffIgnore; import org.javers.core.metamodel.annotation.DiffIgnore;
@ -12,7 +29,6 @@ public abstract class AbstractOldObj<T> {
@DiffIgnore @DiffIgnore
private T oldObject; private T oldObject;
public void setOldObject(T oldObject) { public void setOldObject(T oldObject) {
this.oldObject = oldObject; this.oldObject = oldObject;
} }

View File

@ -1,3 +1,20 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.nebula.aggregate.core; package com.nebula.aggregate.core;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
@ -112,9 +129,9 @@ public class AggregateDiff {
* @param <T> * @param <T>
*/ */
public <T> void objectChangeFunction(Consumer<T> addConsume, public <T> void objectChangeFunction(Consumer<T> addConsume,
Consumer<T> updateConsume, Consumer<T> updateConsume,
Consumer<T> deleteConsume, Consumer<T> deleteConsume,
Class<T> clazz) { Class<T> clazz) {
Changes changes = this.diff.getChanges(); Changes changes = this.diff.getChanges();
for (Change change : changes) { for (Change change : changes) {
if ((change instanceof NewObject && Objects.nonNull(addConsume))) { if ((change instanceof NewObject && Objects.nonNull(addConsume))) {
@ -143,11 +160,11 @@ public class AggregateDiff {
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public static <T> void listChangeFunction(List<T> oldList, public static <T> void listChangeFunction(List<T> oldList,
List<T> newList, List<T> newList,
Class<T> clazz, Class<T> clazz,
Consumer<List<T>> addConsume, Consumer<List<T>> addConsume,
Consumer<List<T>> updateConsume, Consumer<List<T>> updateConsume,
Consumer<List<T>> removeConsume) { Consumer<List<T>> removeConsume) {
initNegativeId(clazz, newList); initNegativeId(clazz, newList);
Diff listDiff = javers.compareCollections(oldList, newList, clazz); Diff listDiff = javers.compareCollections(oldList, newList, clazz);
@ -217,11 +234,11 @@ public class AggregateDiff {
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public static <T> void collectionChangeFunction(Collection<T> oldList, public static <T> void collectionChangeFunction(Collection<T> oldList,
Collection<T> newList, Collection<T> newList,
Class<T> clazz, Class<T> clazz,
Consumer<Map<String, T>> addConsume, Consumer<Map<String, T>> addConsume,
Consumer<Map<String, T>> updateConsume, Consumer<Map<String, T>> updateConsume,
Consumer<Map<String, T>> removeConsume) { Consumer<Map<String, T>> removeConsume) {
Diff listDiff = javers.compareCollections(oldList, newList, clazz); Diff listDiff = javers.compareCollections(oldList, newList, clazz);
@ -291,10 +308,10 @@ public class AggregateDiff {
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public static <T> void simpleListChangeFunction(Collection<T> oldList, public static <T> void simpleListChangeFunction(Collection<T> oldList,
Collection<T> newList, Collection<T> newList,
Class<T> clazz, Class<T> clazz,
Consumer<List<T>> addConsume, Consumer<List<T>> addConsume,
Consumer<List<T>> removeConsume) { Consumer<List<T>> removeConsume) {
Diff listDiff = javers.compareCollections(oldList, newList, clazz); Diff listDiff = javers.compareCollections(oldList, newList, clazz);

View File

@ -1,6 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<parent> <parent>
@ -19,10 +18,10 @@
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>io.github.weihubeats</groupId> <groupId>io.github.weihubeats</groupId>
<artifactId>spring-boot-nebula-web</artifactId> <artifactId>spring-boot-nebula-web</artifactId>
</dependency> </dependency>
<dependency> <dependency>
<groupId>io.github.weihubeats</groupId> <groupId>io.github.weihubeats</groupId>
@ -34,8 +33,6 @@
<artifactId>spring-boot-nebula-distribute-lock</artifactId> <artifactId>spring-boot-nebula-distribute-lock</artifactId>
</dependency> </dependency>
</dependencies> </dependencies>
</project> </project>

View File

@ -1,6 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<parent> <parent>

View File

@ -1,3 +1,20 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.nebula.aop.base; package com.nebula.aop.base;
import lombok.NonNull; import lombok.NonNull;
@ -35,7 +52,7 @@ public class NebulaBaseAnnotationAdvisor extends AbstractPointcutAdvisor impleme
private final Class<? extends Annotation> annotation; private final Class<? extends Annotation> annotation;
public NebulaBaseAnnotationAdvisor(@NonNull MethodInterceptor advice, public NebulaBaseAnnotationAdvisor(@NonNull MethodInterceptor advice,
@NonNull Class<? extends Annotation> annotation) { @NonNull Class<? extends Annotation> annotation) {
this.advice = advice; this.advice = advice;
this.annotation = annotation; this.annotation = annotation;
this.pointcut = buildPointcut(); this.pointcut = buildPointcut();
@ -87,6 +104,7 @@ public class NebulaBaseAnnotationAdvisor extends AbstractPointcutAdvisor impleme
} }
private static class AnnotationMethodMatcher extends StaticMethodMatcher { private static class AnnotationMethodMatcher extends StaticMethodMatcher {
private final Class<? extends Annotation> annotationType; private final Class<? extends Annotation> annotationType;
public AnnotationMethodMatcher(Class<? extends Annotation> annotationType) { public AnnotationMethodMatcher(Class<? extends Annotation> annotationType) {

View File

@ -1,17 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent> <parent>
<artifactId>spring-boot-nebula</artifactId>
<groupId>io.github.weihubeats</groupId> <groupId>io.github.weihubeats</groupId>
<artifactId>spring-boot-nebula</artifactId>
<version>${revision}</version> <version>${revision}</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>spring-boot-nebula-common</artifactId> <artifactId>spring-boot-nebula-common</artifactId>
<dependencies> <dependencies>
<dependency> <dependency>
@ -66,8 +64,6 @@
<artifactId>jackson-datatype-jsr310</artifactId> <artifactId>jackson-datatype-jsr310</artifactId>
</dependency> </dependency>
</dependencies> </dependencies>
</project> </project>

View File

@ -1,3 +1,20 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.nebula.base.exception; package com.nebula.base.exception;
import java.io.PrintWriter; import java.io.PrintWriter;
@ -28,7 +45,7 @@ public class ExceptionUtil {
*/ */
public static RuntimeException unchecked(Throwable e) { public static RuntimeException unchecked(Throwable e) {
if (e instanceof IllegalAccessException || e instanceof IllegalArgumentException if (e instanceof IllegalAccessException || e instanceof IllegalArgumentException
|| e instanceof NoSuchMethodException) { || e instanceof NoSuchMethodException) {
return new IllegalArgumentException(e); return new IllegalArgumentException(e);
} else if (e instanceof InvocationTargetException) { } else if (e instanceof InvocationTargetException) {
return new RuntimeException(((InvocationTargetException) e).getTargetException()); return new RuntimeException(((InvocationTargetException) e).getTargetException());

View File

@ -1,3 +1,20 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.nebula.base.utils; package com.nebula.base.utils;
import java.lang.reflect.Array; import java.lang.reflect.Array;
@ -9,7 +26,6 @@ import java.lang.reflect.Array;
*/ */
public class ArraysUtil { public class ArraysUtil {
// ---------------------------------------------------------------- wrap // ---------------------------------------------------------------- wrap
/** /**
@ -76,7 +92,6 @@ public class ArraysUtil {
return elements; return elements;
} }
// ---------------------------------------------------------------- join // ---------------------------------------------------------------- join
/** /**
@ -110,7 +125,6 @@ public class ArraysUtil {
return result; return result;
} }
/** /**
* Join <code>String</code> arrays. * Join <code>String</code> arrays.
*/ */
@ -318,7 +332,6 @@ public class ArraysUtil {
return result; return result;
} }
// ---------------------------------------------------------------- resize // ---------------------------------------------------------------- resize
/** /**
@ -331,7 +344,6 @@ public class ArraysUtil {
return temp; return temp;
} }
/** /**
* Resizes a <code>String</code> array. * Resizes a <code>String</code> array.
*/ */
@ -413,7 +425,6 @@ public class ArraysUtil {
return temp; return temp;
} }
// ---------------------------------------------------------------- append // ---------------------------------------------------------------- append
/** /**
@ -506,7 +517,6 @@ public class ArraysUtil {
return t; return t;
} }
// ---------------------------------------------------------------- remove // ---------------------------------------------------------------- remove
/** /**
@ -628,7 +638,6 @@ public class ArraysUtil {
return temp; return temp;
} }
// ---------------------------------------------------------------- subarray // ---------------------------------------------------------------- subarray
/** /**
@ -730,7 +739,6 @@ public class ArraysUtil {
return temp; return temp;
} }
// ---------------------------------------------------------------- insert // ---------------------------------------------------------------- insert
/** /**
@ -969,7 +977,6 @@ public class ArraysUtil {
return temp; return temp;
} }
// ---------------------------------------------------------------- insertAt // ---------------------------------------------------------------- insertAt
/** /**
@ -1091,10 +1098,8 @@ public class ArraysUtil {
return temp; return temp;
} }
// ---------------------------------------------------------------- convert // ---------------------------------------------------------------- convert
/** /**
* Converts to primitive array. * Converts to primitive array.
*/ */
@ -1119,7 +1124,6 @@ public class ArraysUtil {
return dest; return dest;
} }
/** /**
* Converts to primitive array. * Converts to primitive array.
*/ */
@ -1144,7 +1148,6 @@ public class ArraysUtil {
return dest; return dest;
} }
/** /**
* Converts to primitive array. * Converts to primitive array.
*/ */
@ -1169,7 +1172,6 @@ public class ArraysUtil {
return dest; return dest;
} }
/** /**
* Converts to primitive array. * Converts to primitive array.
*/ */
@ -1194,7 +1196,6 @@ public class ArraysUtil {
return dest; return dest;
} }
/** /**
* Converts to primitive array. * Converts to primitive array.
*/ */
@ -1219,7 +1220,6 @@ public class ArraysUtil {
return dest; return dest;
} }
/** /**
* Converts to primitive array. * Converts to primitive array.
*/ */
@ -1244,7 +1244,6 @@ public class ArraysUtil {
return dest; return dest;
} }
/** /**
* Converts to primitive array. * Converts to primitive array.
*/ */
@ -1269,7 +1268,6 @@ public class ArraysUtil {
return dest; return dest;
} }
/** /**
* Converts to primitive array. * Converts to primitive array.
*/ */
@ -1294,11 +1292,8 @@ public class ArraysUtil {
return dest; return dest;
} }
// ---------------------------------------------------------------- indexof // ---------------------------------------------------------------- indexof
/** /**
* Finds the first occurrence of an element in an array. * Finds the first occurrence of an element in an array.
*/ */
@ -1651,12 +1646,8 @@ public class ArraysUtil {
return indexOf(array, value, startIndex) != -1; return indexOf(array, value, startIndex) != -1;
} }
// ---------------------------------------------------------------- indexof 2 // ---------------------------------------------------------------- indexof 2
/** /**
* Finds the first occurrence in an array. * Finds the first occurrence in an array.
*/ */
@ -1667,7 +1658,6 @@ public class ArraysUtil {
return indexOf(array, sub) != -1; return indexOf(array, sub) != -1;
} }
/** /**
* Finds the first occurrence in an array from specified given position. * Finds the first occurrence in an array from specified given position.
*/ */
@ -1685,8 +1675,7 @@ public class ArraysUtil {
} }
final int total = endIndex - sublen + 1; final int total = endIndex - sublen + 1;
final byte c = sub[0]; final byte c = sub[0];
mainloop: mainloop: for (int i = startIndex; i < total; i++) {
for (int i = startIndex; i < total; i++) {
if (array[i] != c) { if (array[i] != c) {
continue; continue;
} }
@ -1696,7 +1685,8 @@ public class ArraysUtil {
if (sub[j] != array[k]) { if (sub[j] != array[k]) {
continue mainloop; continue mainloop;
} }
j++; k++; j++;
k++;
} }
return i; return i;
} }
@ -1713,7 +1703,6 @@ public class ArraysUtil {
return indexOf(array, sub) != -1; return indexOf(array, sub) != -1;
} }
/** /**
* Finds the first occurrence in an array from specified given position. * Finds the first occurrence in an array from specified given position.
*/ */
@ -1731,8 +1720,7 @@ public class ArraysUtil {
} }
final int total = endIndex - sublen + 1; final int total = endIndex - sublen + 1;
final char c = sub[0]; final char c = sub[0];
mainloop: mainloop: for (int i = startIndex; i < total; i++) {
for (int i = startIndex; i < total; i++) {
if (array[i] != c) { if (array[i] != c) {
continue; continue;
} }
@ -1742,7 +1730,8 @@ public class ArraysUtil {
if (sub[j] != array[k]) { if (sub[j] != array[k]) {
continue mainloop; continue mainloop;
} }
j++; k++; j++;
k++;
} }
return i; return i;
} }
@ -1759,7 +1748,6 @@ public class ArraysUtil {
return indexOf(array, sub) != -1; return indexOf(array, sub) != -1;
} }
/** /**
* Finds the first occurrence in an array from specified given position. * Finds the first occurrence in an array from specified given position.
*/ */
@ -1777,8 +1765,7 @@ public class ArraysUtil {
} }
final int total = endIndex - sublen + 1; final int total = endIndex - sublen + 1;
final short c = sub[0]; final short c = sub[0];
mainloop: mainloop: for (int i = startIndex; i < total; i++) {
for (int i = startIndex; i < total; i++) {
if (array[i] != c) { if (array[i] != c) {
continue; continue;
} }
@ -1788,7 +1775,8 @@ public class ArraysUtil {
if (sub[j] != array[k]) { if (sub[j] != array[k]) {
continue mainloop; continue mainloop;
} }
j++; k++; j++;
k++;
} }
return i; return i;
} }
@ -1805,7 +1793,6 @@ public class ArraysUtil {
return indexOf(array, sub) != -1; return indexOf(array, sub) != -1;
} }
/** /**
* Finds the first occurrence in an array from specified given position. * Finds the first occurrence in an array from specified given position.
*/ */
@ -1823,8 +1810,7 @@ public class ArraysUtil {
} }
final int total = endIndex - sublen + 1; final int total = endIndex - sublen + 1;
final int c = sub[0]; final int c = sub[0];
mainloop: mainloop: for (int i = startIndex; i < total; i++) {
for (int i = startIndex; i < total; i++) {
if (array[i] != c) { if (array[i] != c) {
continue; continue;
} }
@ -1834,7 +1820,8 @@ public class ArraysUtil {
if (sub[j] != array[k]) { if (sub[j] != array[k]) {
continue mainloop; continue mainloop;
} }
j++; k++; j++;
k++;
} }
return i; return i;
} }
@ -1851,7 +1838,6 @@ public class ArraysUtil {
return indexOf(array, sub) != -1; return indexOf(array, sub) != -1;
} }
/** /**
* Finds the first occurrence in an array from specified given position. * Finds the first occurrence in an array from specified given position.
*/ */
@ -1869,8 +1855,7 @@ public class ArraysUtil {
} }
final int total = endIndex - sublen + 1; final int total = endIndex - sublen + 1;
final long c = sub[0]; final long c = sub[0];
mainloop: mainloop: for (int i = startIndex; i < total; i++) {
for (int i = startIndex; i < total; i++) {
if (array[i] != c) { if (array[i] != c) {
continue; continue;
} }
@ -1880,7 +1865,8 @@ public class ArraysUtil {
if (sub[j] != array[k]) { if (sub[j] != array[k]) {
continue mainloop; continue mainloop;
} }
j++; k++; j++;
k++;
} }
return i; return i;
} }
@ -1897,7 +1883,6 @@ public class ArraysUtil {
return indexOf(array, sub) != -1; return indexOf(array, sub) != -1;
} }
/** /**
* Finds the first occurrence in an array from specified given position. * Finds the first occurrence in an array from specified given position.
*/ */
@ -1915,8 +1900,7 @@ public class ArraysUtil {
} }
final int total = endIndex - sublen + 1; final int total = endIndex - sublen + 1;
final boolean c = sub[0]; final boolean c = sub[0];
mainloop: mainloop: for (int i = startIndex; i < total; i++) {
for (int i = startIndex; i < total; i++) {
if (array[i] != c) { if (array[i] != c) {
continue; continue;
} }
@ -1926,7 +1910,8 @@ public class ArraysUtil {
if (sub[j] != array[k]) { if (sub[j] != array[k]) {
continue mainloop; continue mainloop;
} }
j++; k++; j++;
k++;
} }
return i; return i;
} }
@ -1943,7 +1928,6 @@ public class ArraysUtil {
return indexOf(array, sub) != -1; return indexOf(array, sub) != -1;
} }
/** /**
* Finds the first occurrence in an array from specified given position. * Finds the first occurrence in an array from specified given position.
*/ */
@ -1961,8 +1945,7 @@ public class ArraysUtil {
} }
final int total = endIndex - sublen + 1; final int total = endIndex - sublen + 1;
final float c = sub[0]; final float c = sub[0];
mainloop: mainloop: for (int i = startIndex; i < total; i++) {
for (int i = startIndex; i < total; i++) {
if (Float.compare(array[i], c) != 0) { if (Float.compare(array[i], c) != 0) {
continue; continue;
} }
@ -1972,7 +1955,8 @@ public class ArraysUtil {
if (Float.compare(sub[j], array[k]) != 0) { if (Float.compare(sub[j], array[k]) != 0) {
continue mainloop; continue mainloop;
} }
j++; k++; j++;
k++;
} }
return i; return i;
} }
@ -1989,7 +1973,6 @@ public class ArraysUtil {
return indexOf(array, sub) != -1; return indexOf(array, sub) != -1;
} }
/** /**
* Finds the first occurrence in an array from specified given position. * Finds the first occurrence in an array from specified given position.
*/ */
@ -2007,8 +1990,7 @@ public class ArraysUtil {
} }
final int total = endIndex - sublen + 1; final int total = endIndex - sublen + 1;
final double c = sub[0]; final double c = sub[0];
mainloop: mainloop: for (int i = startIndex; i < total; i++) {
for (int i = startIndex; i < total; i++) {
if (Double.compare(array[i], c) != 0) { if (Double.compare(array[i], c) != 0) {
continue; continue;
} }
@ -2018,14 +2000,14 @@ public class ArraysUtil {
if (Double.compare(sub[j], array[k]) != 0) { if (Double.compare(sub[j], array[k]) != 0) {
continue mainloop; continue mainloop;
} }
j++; k++; j++;
k++;
} }
return i; return i;
} }
return -1; return -1;
} }
// ---------------------------------------------------------------- toString // ---------------------------------------------------------------- toString
/** /**
@ -2238,7 +2220,6 @@ public class ArraysUtil {
return sb.toString(); return sb.toString();
} }
/** /**
* Converts an array to string array. * Converts an array to string array.
*/ */

View File

@ -1,3 +1,20 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.nebula.base.utils; package com.nebula.base.utils;
import java.nio.charset.Charset; import java.nio.charset.Charset;
@ -433,6 +450,6 @@ public class CharUtil {
return HEX_CHARS[i]; return HEX_CHARS[i];
} }
public static final char[] HEX_CHARS = new char[] {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}; public static final char[] HEX_CHARS = new char[]{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
} }

View File

@ -1,3 +1,20 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.nebula.base.utils; package com.nebula.base.utils;
import java.lang.reflect.Array; import java.lang.reflect.Array;
@ -32,20 +49,20 @@ public interface ClassLoaderStrategy {
/** /**
* List of primitive type names. * List of primitive type names.
*/ */
public static final String[] PRIMITIVE_TYPE_NAMES = new String[] { public static final String[] PRIMITIVE_TYPE_NAMES = new String[]{
"boolean", "byte", "char", "double", "float", "int", "long", "short", "boolean", "byte", "char", "double", "float", "int", "long", "short",
}; };
/** /**
* List of primitive types that matches names list. * List of primitive types that matches names list.
*/ */
public static final Class[] PRIMITIVE_TYPES = new Class[] { public static final Class[] PRIMITIVE_TYPES = new Class[]{
boolean.class, byte.class, char.class, double.class, float.class, int.class, long.class, short.class, boolean.class, byte.class, char.class, double.class, float.class, int.class, long.class, short.class,
}; };
/** /**
* List of primitive bytecode characters that matches names list. * List of primitive bytecode characters that matches names list.
*/ */
public static final char[] PRIMITIVE_BYTECODE_NAME = new char[] { public static final char[] PRIMITIVE_BYTECODE_NAME = new char[]{
'Z', 'B', 'C', 'D', 'F', 'I', 'J', 'S' 'Z', 'B', 'C', 'D', 'F', 'I', 'J', 'S'
}; };
// ---------------------------------------------------------------- flags // ---------------------------------------------------------------- flags
@ -147,7 +164,7 @@ public interface ClassLoaderStrategy {
} }
// try #3 - using caller classloader, similar as Class.forName() // try #3 - using caller classloader, similar as Class.forName()
//Class callerClass = ReflectUtil.getCallerClass(2); // Class callerClass = ReflectUtil.getCallerClass(2);
final Class callerClass = ClassUtil.getCallerClass(); final Class callerClass = ClassUtil.getCallerClass();
final ClassLoader callerClassLoader = callerClass.getClassLoader(); final ClassLoader callerClassLoader = callerClass.getClassLoader();
@ -201,7 +218,7 @@ public interface ClassLoaderStrategy {
* Loads array class using component type. * Loads array class using component type.
*/ */
protected Class loadArrayClassByComponentType(final String className, protected Class loadArrayClassByComponentType(final String className,
final ClassLoader classLoader) throws ClassNotFoundException { final ClassLoader classLoader) throws ClassNotFoundException {
final int ndx = className.indexOf('['); final int ndx = className.indexOf('[');
final int multi = StringUtils.count(className, '['); final int multi = StringUtils.count(className, '[');
@ -216,9 +233,9 @@ public interface ClassLoaderStrategy {
final int[] multiSizes; final int[] multiSizes;
if (multi == 2) { if (multi == 2) {
multiSizes = new int[] {0, 0}; multiSizes = new int[]{0, 0};
} else if (multi == 3) { } else if (multi == 3) {
multiSizes = new int[] {0, 0, 0}; multiSizes = new int[]{0, 0, 0};
} else { } else {
multiSizes = (int[]) Array.newInstance(int.class, multi); multiSizes = (int[]) Array.newInstance(int.class, multi);
} }

View File

@ -1,3 +1,20 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.nebula.base.utils; package com.nebula.base.utils;
import com.nebula.base.utils.io.IOUtil; import com.nebula.base.utils.io.IOUtil;
@ -42,7 +59,7 @@ public class ClassLoaderUtil {
return Thread.currentThread().getContextClassLoader(); return Thread.currentThread().getContextClassLoader();
} else { } else {
return AccessController.doPrivileged( return AccessController.doPrivileged(
(PrivilegedAction<ClassLoader>) () -> Thread.currentThread().getContextClassLoader()); (PrivilegedAction<ClassLoader>) () -> Thread.currentThread().getContextClassLoader());
} }
} }
@ -54,7 +71,7 @@ public class ClassLoaderUtil {
return ClassLoader.getSystemClassLoader(); return ClassLoader.getSystemClassLoader();
} else { } else {
return AccessController.doPrivileged( return AccessController.doPrivileged(
(PrivilegedAction<ClassLoader>) ClassLoader::getSystemClassLoader); (PrivilegedAction<ClassLoader>) ClassLoader::getSystemClassLoader);
} }
} }
@ -140,7 +157,7 @@ public class ClassLoaderUtil {
* Opens a class of the specified name for reading using provided class loader. * Opens a class of the specified name for reading using provided class loader.
*/ */
public static InputStream getClassAsStream(final String className, public static InputStream getClassAsStream(final String className,
final ClassLoader classLoader) throws IOException { final ClassLoader classLoader) throws IOException {
return ResourcesUtil.getResourceAsStream(ClassUtil.convertClassNameToFileName(className), classLoader); return ResourcesUtil.getResourceAsStream(ClassUtil.convertClassNameToFileName(className), classLoader);
} }

View File

@ -1,3 +1,20 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.nebula.base.utils; package com.nebula.base.utils;
import java.io.File; import java.io.File;
@ -251,26 +268,26 @@ public class ClassUtil {
if (Modifier.isVolatile(method.getModifiers())) { if (Modifier.isVolatile(method.getModifiers())) {
continue; continue;
} }
// if (Modifier.isAbstract(method.getModifiers())) { // if (Modifier.isAbstract(method.getModifiers())) {
// continue; // continue;
// } // }
if (top) { // add all top declared methods if (top) { // add all top declared methods
methodList.add(method); methodList.add(method);
continue; continue;
} }
final int modifier = method.getModifiers(); final int modifier = method.getModifiers();
if (Modifier.isPrivate(modifier)) { if (Modifier.isPrivate(modifier)) {
continue; // ignore super private methods continue; // ignore super private methods
} }
if (Modifier.isAbstract(modifier)) { // ignore super abstract methods if (Modifier.isAbstract(modifier)) { // ignore super abstract methods
continue; continue;
} }
if (Modifier.isPublic(modifier)) { if (Modifier.isPublic(modifier)) {
addMethodIfNotExist(methodList, method); // add super public methods addMethodIfNotExist(methodList, method); // add super public methods
continue; continue;
} }
if (Modifier.isProtected(modifier)) { if (Modifier.isProtected(modifier)) {
addMethodIfNotExist(methodList, method); // add super protected methods addMethodIfNotExist(methodList, method); // add super protected methods
continue; continue;
} }
// add super default methods from the same package // add super default methods from the same package
@ -281,8 +298,7 @@ public class ClassUtil {
} }
} }
top = false; top = false;
} } while ((clazz = clazz.getSuperclass()) != limit);
while ((clazz = clazz.getSuperclass()) != limit);
final Method[] methods = new Method[methodList.size()]; final Method[] methods = new Method[methodList.size()];
for (int i = 0; i < methods.length; i++) { for (int i = 0; i < methods.length; i++) {
@ -317,20 +333,20 @@ public class ClassUtil {
} }
final Field[] declaredFields = clazz.getDeclaredFields(); final Field[] declaredFields = clazz.getDeclaredFields();
for (final Field field : declaredFields) { for (final Field field : declaredFields) {
if (top) { // add all top declared fields if (top) { // add all top declared fields
fieldList.add(field); fieldList.add(field);
continue; continue;
} }
final int modifier = field.getModifiers(); final int modifier = field.getModifiers();
if (Modifier.isPrivate(modifier)) { if (Modifier.isPrivate(modifier)) {
continue; // ignore super private fields continue; // ignore super private fields
} }
if (Modifier.isPublic(modifier)) { if (Modifier.isPublic(modifier)) {
addFieldIfNotExist(fieldList, field); // add super public methods addFieldIfNotExist(fieldList, field); // add super public methods
continue; continue;
} }
if (Modifier.isProtected(modifier)) { if (Modifier.isProtected(modifier)) {
addFieldIfNotExist(fieldList, field); // add super protected methods addFieldIfNotExist(fieldList, field); // add super protected methods
continue; continue;
} }
// add super default methods from the same package // add super default methods from the same package
@ -341,8 +357,7 @@ public class ClassUtil {
} }
} }
top = false; top = false;
} } while ((clazz = clazz.getSuperclass()) != limit);
while ((clazz = clazz.getSuperclass()) != limit);
final Field[] fields = new Field[fieldList.size()]; final Field[] fields = new Field[fieldList.size()];
for (int i = 0; i < fields.length; i++) { for (int i = 0; i < fields.length; i++) {
@ -524,7 +539,7 @@ public class ClassUtil {
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public static <T> T newInstance(final Class<T> clazz, public static <T> T newInstance(final Class<T> clazz,
final Object... params) throws InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException { final Object... params) throws InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException {
if (params.length == 0) { if (params.length == 0) {
return newInstance(clazz); return newInstance(clazz);
} }
@ -549,7 +564,7 @@ public class ClassUtil {
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public static <T> T newInstance( public static <T> T newInstance(
final Class<T> type) throws IllegalAccessException, InstantiationException, NoSuchMethodException, InvocationTargetException { final Class<T> type) throws IllegalAccessException, InstantiationException, NoSuchMethodException, InvocationTargetException {
if (type.isPrimitive()) { if (type.isPrimitive()) {
if (type == int.class) { if (type == int.class) {
return (T) Integer.valueOf(0); return (T) Integer.valueOf(0);
@ -688,16 +703,16 @@ public class ClassUtil {
final String methodName = method.getName(); final String methodName = method.getName();
final Class returnType = method.getReturnType(); final Class returnType = method.getReturnType();
final Class[] paramTypes = method.getParameterTypes(); final Class[] paramTypes = method.getParameterTypes();
if (methodName.startsWith(METHOD_GET_PREFIX)) { // getter method must starts with 'get' and it is not getClass() if (methodName.startsWith(METHOD_GET_PREFIX)) { // getter method must starts with 'get' and it is not getClass()
if ((returnType != null) && (paramTypes.length == 0)) { // getter must have a return type and no arguments if ((returnType != null) && (paramTypes.length == 0)) { // getter must have a return type and no arguments
return true; return true;
} }
} else if (methodName.startsWith(METHOD_IS_PREFIX)) { // ister must starts with 'is' } else if (methodName.startsWith(METHOD_IS_PREFIX)) { // ister must starts with 'is'
if ((returnType != null) && (paramTypes.length == 0)) { // ister must have return type and no arguments if ((returnType != null) && (paramTypes.length == 0)) { // ister must have return type and no arguments
return true; return true;
} }
} else if (methodName.startsWith(METHOD_SET_PREFIX)) { // setter must start with a 'set' } else if (methodName.startsWith(METHOD_SET_PREFIX)) { // setter must start with a 'set'
if (paramTypes.length == 1) { // setter must have just one argument if (paramTypes.length == 1) { // setter must have just one argument
return true; return true;
} }
} }
@ -718,12 +733,12 @@ public class ClassUtil {
final String methodName = method.getName(); final String methodName = method.getName();
final Class returnType = method.getReturnType(); final Class returnType = method.getReturnType();
final Class[] paramTypes = method.getParameterTypes(); final Class[] paramTypes = method.getParameterTypes();
if (methodName.startsWith(METHOD_GET_PREFIX)) { // getter method must starts with 'get' and it is not getClass() if (methodName.startsWith(METHOD_GET_PREFIX)) { // getter method must starts with 'get' and it is not getClass()
if ((returnType != null) && (paramTypes.length == 0)) { // getter must have a return type and no arguments if ((returnType != null) && (paramTypes.length == 0)) { // getter must have a return type and no arguments
return 3; return 3;
} }
} else if (methodName.startsWith(METHOD_IS_PREFIX)) { // ister must starts with 'is' } else if (methodName.startsWith(METHOD_IS_PREFIX)) { // ister must starts with 'is'
if ((returnType != null) && (paramTypes.length == 0)) { // ister must have return type and no arguments if ((returnType != null) && (paramTypes.length == 0)) { // ister must have return type and no arguments
return 2; return 2;
} }
} }
@ -756,8 +771,8 @@ public class ClassUtil {
} }
final String methodName = method.getName(); final String methodName = method.getName();
final Class[] paramTypes = method.getParameterTypes(); final Class[] paramTypes = method.getParameterTypes();
if (methodName.startsWith(METHOD_SET_PREFIX)) { // setter must start with a 'set' if (methodName.startsWith(METHOD_SET_PREFIX)) { // setter must start with a 'set'
if (paramTypes.length == 1) { // setter must have just one argument if (paramTypes.length == 1) { // setter must have just one argument
return 3; return 3;
} }
} }
@ -840,7 +855,7 @@ public class ClassUtil {
if (type instanceof Class) { if (type instanceof Class) {
final Class clazz = (Class) type; final Class clazz = (Class) type;
if (clazz.isArray()) { if (clazz.isArray()) {
return new Class[] {clazz.getComponentType()}; return new Class[]{clazz.getComponentType()};
} }
} else if (type instanceof ParameterizedType) { } else if (type instanceof ParameterizedType) {
final ParameterizedType pt = (ParameterizedType) type; final ParameterizedType pt = (ParameterizedType) type;
@ -865,7 +880,7 @@ public class ClassUtil {
return null; return null;
} }
return new Class[] {rawType}; return new Class[]{rawType};
} }
return null; return null;
} }
@ -1107,6 +1122,7 @@ public class ClassUtil {
// ---------------------------------------------------------------- caller // ---------------------------------------------------------------- caller
private static class ReflectUtilSecurityManager extends SecurityManager { private static class ReflectUtilSecurityManager extends SecurityManager {
public Class getCallerClass(final int callStackDepth) { public Class getCallerClass(final int callStackDepth) {
return getClassContext()[callStackDepth + 1]; return getClassContext()[callStackDepth + 1];
} }
@ -1247,7 +1263,7 @@ public class ClassUtil {
*/ */
public static JarFile jarFileOf(final Class<?> klass) { public static JarFile jarFileOf(final Class<?> klass) {
final URL url = klass.getResource( final URL url = klass.getResource(
"/" + klass.getName().replace('.', '/') + ".class"); "/" + klass.getName().replace('.', '/') + ".class");
if (url == null) { if (url == null) {
return null; return null;

View File

@ -1,3 +1,20 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.nebula.base.utils; package com.nebula.base.utils;
import java.lang.reflect.Field; import java.lang.reflect.Field;
@ -129,8 +146,8 @@ public class DataUtils {
*/ */
public static <T, S> T getDefaultValue(S value, T defaultValue, Function<S, T> function) { public static <T, S> T getDefaultValue(S value, T defaultValue, Function<S, T> function) {
return isNotEmpty(value) return isNotEmpty(value)
? function.apply(value) ? function.apply(value)
: defaultValue; : defaultValue;
} }
/** /**
@ -145,8 +162,8 @@ public class DataUtils {
public static <T, S> T getDefaultValueSafety(S value, T defaultValue, Function<S, T> function) { public static <T, S> T getDefaultValueSafety(S value, T defaultValue, Function<S, T> function) {
try { try {
return isNotEmpty(value) return isNotEmpty(value)
? function.apply(value) ? function.apply(value)
: defaultValue; : defaultValue;
} catch (Exception e) { } catch (Exception e) {
return defaultValue; return defaultValue;
} }

View File

@ -1,3 +1,20 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.nebula.base.utils; package com.nebula.base.utils;
import com.nebula.base.utils.io.IOUtil; import com.nebula.base.utils.io.IOUtil;
@ -47,8 +64,7 @@ public interface DigestEngine {
while (dis.read() != -1) { while (dis.read() != -1) {
} }
} } finally {
finally {
IOUtil.close(dis); IOUtil.close(dis);
IOUtil.close(bis); IOUtil.close(bis);
IOUtil.close(fis); IOUtil.close(fis);

View File

@ -1,3 +1,20 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.nebula.base.utils; package com.nebula.base.utils;
import com.fasterxml.jackson.databind.module.SimpleModule; import com.fasterxml.jackson.databind.module.SimpleModule;
@ -17,7 +34,6 @@ import java.time.LocalTime;
*/ */
public class JacksonTimeModule extends SimpleModule { public class JacksonTimeModule extends SimpleModule {
public JacksonTimeModule() { public JacksonTimeModule() {
super(PackageVersion.VERSION); super(PackageVersion.VERSION);
this.addDeserializer(LocalDateTime.class, new LocalDateTimeDeserializer(TimeUtil.DATETIME_FORMAT)); this.addDeserializer(LocalDateTime.class, new LocalDateTimeDeserializer(TimeUtil.DATETIME_FORMAT));
@ -28,5 +44,4 @@ public class JacksonTimeModule extends SimpleModule {
this.addSerializer(LocalTime.class, new LocalTimeSerializer(TimeUtil.TIME_FORMAT)); this.addSerializer(LocalTime.class, new LocalTimeSerializer(TimeUtil.TIME_FORMAT));
} }
} }

View File

@ -1,3 +1,20 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.nebula.base.utils; package com.nebula.base.utils;
import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude;
@ -33,8 +50,7 @@ public class JsonUtil {
public static <T> String toJSONString(T value) { public static <T> String toJSONString(T value) {
try { try {
return getInstance().writeValueAsString(value); return getInstance().writeValueAsString(value);
} } catch (Exception e) {
catch (Exception e) {
log.error(e.getMessage(), e); log.error(e.getMessage(), e);
} }
return null; return null;
@ -43,8 +59,7 @@ public class JsonUtil {
public static <T> String toJSONString(ObjectMapper objectMapper, T value) { public static <T> String toJSONString(ObjectMapper objectMapper, T value) {
try { try {
return objectMapper.writeValueAsString(value); return objectMapper.writeValueAsString(value);
} } catch (Exception e) {
catch (Exception e) {
log.error(e.getMessage(), e); log.error(e.getMessage(), e);
} }
return null; return null;
@ -70,8 +85,7 @@ public class JsonUtil {
public static byte[] toJsonAsBytes(Object object) { public static byte[] toJsonAsBytes(Object object) {
try { try {
return getInstance().writeValueAsBytes(object); return getInstance().writeValueAsBytes(object);
} } catch (JsonProcessingException e) {
catch (JsonProcessingException e) {
throw ExceptionUtil.unchecked(e); throw ExceptionUtil.unchecked(e);
} }
} }
@ -87,8 +101,7 @@ public class JsonUtil {
public static <T> T json2JavaBean(String content, Class<T> valueType) { public static <T> T json2JavaBean(String content, Class<T> valueType) {
try { try {
return getInstance().readValue(content, valueType); return getInstance().readValue(content, valueType);
} } catch (Exception e) {
catch (Exception e) {
log.error(e.getMessage(), e); log.error(e.getMessage(), e);
} }
return null; return null;
@ -105,8 +118,7 @@ public class JsonUtil {
public static <T> T json2JavaBean(String content, TypeReference<T> typeReference) { public static <T> T json2JavaBean(String content, TypeReference<T> typeReference) {
try { try {
return getInstance().readValue(content, typeReference); return getInstance().readValue(content, typeReference);
} } catch (IOException e) {
catch (IOException e) {
throw ExceptionUtil.unchecked(e); throw ExceptionUtil.unchecked(e);
} }
} }
@ -122,13 +134,11 @@ public class JsonUtil {
public static <T> T json2JavaBean(byte[] bytes, Class<T> valueType) { public static <T> T json2JavaBean(byte[] bytes, Class<T> valueType) {
try { try {
return getInstance().readValue(bytes, valueType); return getInstance().readValue(bytes, valueType);
} } catch (IOException e) {
catch (IOException e) {
throw ExceptionUtil.unchecked(e); throw ExceptionUtil.unchecked(e);
} }
} }
/** /**
* 将json反序列化成对象 * 将json反序列化成对象
* *
@ -140,8 +150,7 @@ public class JsonUtil {
public static <T> T json2JavaBean(byte[] bytes, TypeReference<T> typeReference) { public static <T> T json2JavaBean(byte[] bytes, TypeReference<T> typeReference) {
try { try {
return getInstance().readValue(bytes, typeReference); return getInstance().readValue(bytes, typeReference);
} } catch (IOException e) {
catch (IOException e) {
throw ExceptionUtil.unchecked(e); throw ExceptionUtil.unchecked(e);
} }
} }
@ -157,8 +166,7 @@ public class JsonUtil {
public static <T> T json2JavaBean(InputStream in, Class<T> valueType) { public static <T> T json2JavaBean(InputStream in, Class<T> valueType) {
try { try {
return getInstance().readValue(in, valueType); return getInstance().readValue(in, valueType);
} } catch (IOException e) {
catch (IOException e) {
throw ExceptionUtil.unchecked(e); throw ExceptionUtil.unchecked(e);
} }
} }
@ -174,8 +182,7 @@ public class JsonUtil {
public static <T> T json2JavaBean(InputStream in, TypeReference<T> typeReference) { public static <T> T json2JavaBean(InputStream in, TypeReference<T> typeReference) {
try { try {
return getInstance().readValue(in, typeReference); return getInstance().readValue(in, typeReference);
} } catch (IOException e) {
catch (IOException e) {
throw ExceptionUtil.unchecked(e); throw ExceptionUtil.unchecked(e);
} }
} }
@ -188,8 +195,7 @@ public class JsonUtil {
JavaType javaType = getInstance().getTypeFactory().constructParametricType(List.class, valueTypeRef); JavaType javaType = getInstance().getTypeFactory().constructParametricType(List.class, valueTypeRef);
try { try {
return getInstance().readValue(json, javaType); return getInstance().readValue(json, javaType);
} } catch (JsonProcessingException e) {
catch (JsonProcessingException e) {
log.error(e.getMessage(), e); log.error(e.getMessage(), e);
} }
return objectList; return objectList;
@ -200,14 +206,12 @@ public class JsonUtil {
List<T> objectList = Collections.emptyList(); List<T> objectList = Collections.emptyList();
try { try {
return reader.readValue(jsonNode); return reader.readValue(jsonNode);
} } catch (IOException e) {
catch (IOException e) {
log.error(e.getMessage(), e); log.error(e.getMessage(), e);
} }
return objectList; return objectList;
} }
/** /**
* json to Map * json to Map
* @param content * @param content
@ -216,8 +220,7 @@ public class JsonUtil {
public static Map<String, Object> json2Map(String content) { public static Map<String, Object> json2Map(String content) {
try { try {
return getInstance().readValue(content, Map.class); return getInstance().readValue(content, Map.class);
} } catch (IOException e) {
catch (IOException e) {
log.error(e.getMessage(), e); log.error(e.getMessage(), e);
} }
return null; return null;
@ -232,8 +235,7 @@ public class JsonUtil {
result.put(entry.getKey(), toPojo(entry.getValue(), valueTypeRef)); result.put(entry.getKey(), toPojo(entry.getValue(), valueTypeRef));
} }
return result; return result;
} } catch (IOException e) {
catch (IOException e) {
log.error(e.getMessage(), e); log.error(e.getMessage(), e);
} }
return null; return null;
@ -252,8 +254,7 @@ public class JsonUtil {
public static JsonNode json2JsonNode(String jsonString) { public static JsonNode json2JsonNode(String jsonString) {
try { try {
return getInstance().readTree(jsonString); return getInstance().readTree(jsonString);
} } catch (IOException e) {
catch (IOException e) {
throw ExceptionUtil.unchecked(e); throw ExceptionUtil.unchecked(e);
} }
} }
@ -266,8 +267,7 @@ public class JsonUtil {
public static String jsonNodeToString(JsonNode jsonNode) { public static String jsonNodeToString(JsonNode jsonNode) {
try { try {
return getInstance().writeValueAsString(jsonNode); return getInstance().writeValueAsString(jsonNode);
} } catch (IOException e) {
catch (IOException e) {
throw ExceptionUtil.unchecked(e); throw ExceptionUtil.unchecked(e);
} }
} }
@ -281,8 +281,7 @@ public class JsonUtil {
public static JsonNode byte2JsonNode(byte[] content) { public static JsonNode byte2JsonNode(byte[] content) {
try { try {
return getInstance().readTree(content); return getInstance().readTree(content);
} } catch (IOException e) {
catch (IOException e) {
throw ExceptionUtil.unchecked(e); throw ExceptionUtil.unchecked(e);
} }
} }
@ -296,8 +295,7 @@ public class JsonUtil {
public static JsonNode json2JsonNode(InputStream in) { public static JsonNode json2JsonNode(InputStream in) {
try { try {
return getInstance().readTree(in); return getInstance().readTree(in);
} } catch (IOException e) {
catch (IOException e) {
throw ExceptionUtil.unchecked(e); throw ExceptionUtil.unchecked(e);
} }
} }
@ -311,8 +309,7 @@ public class JsonUtil {
public static JsonNode json2JsonNode(byte[] content) { public static JsonNode json2JsonNode(byte[] content) {
try { try {
return getInstance().readTree(content); return getInstance().readTree(content);
} } catch (IOException e) {
catch (IOException e) {
throw ExceptionUtil.unchecked(e); throw ExceptionUtil.unchecked(e);
} }
} }
@ -326,8 +323,7 @@ public class JsonUtil {
public static JsonNode json2JsonNode(JsonParser jsonParser) { public static JsonNode json2JsonNode(JsonParser jsonParser) {
try { try {
return getInstance().readTree(jsonParser); return getInstance().readTree(jsonParser);
} } catch (IOException e) {
catch (IOException e) {
throw ExceptionUtil.unchecked(e); throw ExceptionUtil.unchecked(e);
} }
} }
@ -336,7 +332,6 @@ public class JsonUtil {
return JacksonHolder.INSTANCE; return JacksonHolder.INSTANCE;
} }
private static class JacksonHolder { private static class JacksonHolder {
private static final ObjectMapper INSTANCE = new JacksonObjectMapper(); private static final ObjectMapper INSTANCE = new JacksonObjectMapper();
@ -350,27 +345,27 @@ public class JsonUtil {
public JacksonObjectMapper() { public JacksonObjectMapper() {
super(); super();
//设置地点为中国 // 设置地点为中国
super.setLocale(CHINA); super.setLocale(CHINA);
super.setSerializationInclusion(JsonInclude.Include.NON_NULL); super.setSerializationInclusion(JsonInclude.Include.NON_NULL);
//去掉默认的时间戳格式 // 去掉默认的时间戳格式
super.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false); super.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
//设置为中国上海时区 // 设置为中国上海时区
super.setTimeZone(TimeZone.getTimeZone(ZoneId.systemDefault())); super.setTimeZone(TimeZone.getTimeZone(ZoneId.systemDefault()));
//序列化时日期的统一格式 // 序列化时日期的统一格式
super.setDateFormat(new SimpleDateFormat(TimeUtil.YYYYMMddHHmmss, Locale.CHINA)); super.setDateFormat(new SimpleDateFormat(TimeUtil.YYYYMMddHHmmss, Locale.CHINA));
//序列化处理 // 序列化处理
super.configure(JsonReadFeature.ALLOW_UNESCAPED_CONTROL_CHARS.mappedFeature(), true); super.configure(JsonReadFeature.ALLOW_UNESCAPED_CONTROL_CHARS.mappedFeature(), true);
super.configure(JsonReadFeature.ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER.mappedFeature(), true); super.configure(JsonReadFeature.ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER.mappedFeature(), true);
super.findAndRegisterModules(); super.findAndRegisterModules();
//失败处理 // 失败处理
super.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false); super.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
super.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); super.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
//单引号处理 // 单引号处理
super.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true); super.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true);
//反序列化时属性不存在的兼容处理 // 反序列化时属性不存在的兼容处理
super.getDeserializationConfig().withoutFeatures(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); super.getDeserializationConfig().withoutFeatures(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
//日期格式化 // 日期格式化
super.registerModule(new JacksonTimeModule()); super.registerModule(new JacksonTimeModule());
super.findAndRegisterModules(); super.findAndRegisterModules();
} }

View File

@ -1,3 +1,20 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.nebula.base.utils; package com.nebula.base.utils;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@ -94,5 +111,4 @@ public enum PatternEnum {
return pattern.matcher(input).matches(); return pattern.matcher(input).matches();
} }
} }

View File

@ -1,3 +1,20 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.nebula.base.utils; package com.nebula.base.utils;
import java.io.Serializable; import java.io.Serializable;

View File

@ -1,3 +1,20 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.nebula.base.utils; package com.nebula.base.utils;
import java.beans.BeanInfo; import java.beans.BeanInfo;
@ -25,7 +42,6 @@ public class ReflectionUtils {
private static final Logger logger = LoggerFactory.getLogger(ReflectionUtils.class); private static final Logger logger = LoggerFactory.getLogger(ReflectionUtils.class);
/** /**
* 获取 Function * 获取 Function
* @param func * @param func
@ -72,9 +88,9 @@ public class ReflectionUtils {
*/ */
public static <T> boolean isExistFieldName(String fieldName, Class<T> clazz) { public static <T> boolean isExistFieldName(String fieldName, Class<T> clazz) {
boolean flag = false; boolean flag = false;
//获取这个类的所有属性 // 获取这个类的所有属性
Field[] fields = clazz.getDeclaredFields(); Field[] fields = clazz.getDeclaredFields();
//循环遍历所有的fields // 循环遍历所有的fields
for (Field field : fields) { for (Field field : fields) {
if (field.getName().equals(fieldName)) { if (field.getName().equals(fieldName)) {
flag = true; flag = true;
@ -86,9 +102,9 @@ public class ReflectionUtils {
public static <T, V extends Annotation> boolean isExistFieldName(String fieldName, Class<T> clazz, Class<V> annotationClass) { public static <T, V extends Annotation> boolean isExistFieldName(String fieldName, Class<T> clazz, Class<V> annotationClass) {
boolean flag = false; boolean flag = false;
//获取这个类的所有属性 // 获取这个类的所有属性
Field[] fields = clazz.getDeclaredFields(); Field[] fields = clazz.getDeclaredFields();
//循环遍历所有的fields // 循环遍历所有的fields
for (Field field : fields) { for (Field field : fields) {
if (field.getName().equals(fieldName) && Objects.nonNull(field.getAnnotation(annotationClass))) { if (field.getName().equals(fieldName) && Objects.nonNull(field.getAnnotation(annotationClass))) {
flag = true; flag = true;
@ -98,7 +114,6 @@ public class ReflectionUtils {
return flag; return flag;
} }
/** /**
* 获取指定属性 * 获取指定属性
* *

View File

@ -1,3 +1,20 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.nebula.base.utils; package com.nebula.base.utils;
import java.util.ArrayList; import java.util.ArrayList;
@ -270,7 +287,7 @@ public class RegexUtils {
var length = str.length() - 1; var length = str.length() - 1;
int fuzzyLength = lastIndexOf - firstIndex + 1; int fuzzyLength = lastIndexOf - firstIndex + 1;
//todo 后续再重构兼容星不连续类型字段 // todo 后续再重构兼容星不连续类型字段
if (fuzzyLength == length + 1) { if (fuzzyLength == length + 1) {
throw new RuntimeException("暂时不兼容该类型字段"); throw new RuntimeException("暂时不兼容该类型字段");
} }

View File

@ -1,3 +1,20 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.nebula.base.utils; package com.nebula.base.utils;
import com.nebula.base.utils.io.IOUtil; import com.nebula.base.utils.io.IOUtil;
@ -80,8 +97,7 @@ public class ResourcesUtil {
try { try {
final char[] data = IOUtil.readChars(inputStream); final char[] data = IOUtil.readChars(inputStream);
return new String(data); return new String(data);
} } finally {
finally {
IOUtil.close(inputStream); IOUtil.close(inputStream);
} }
} }
@ -122,5 +138,4 @@ public class ResourcesUtil {
return null; return null;
} }
} }

View File

@ -1,3 +1,20 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.nebula.base.utils; package com.nebula.base.utils;
/** /**

View File

@ -1,3 +1,20 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.nebula.base.utils; package com.nebula.base.utils;
import com.google.common.base.Joiner; import com.google.common.base.Joiner;
@ -124,7 +141,7 @@ public class StringUtils {
public static String[] splitc(final String src, final char[] delimiters) { public static String[] splitc(final String src, final char[] delimiters) {
if ((delimiters.length == 0) || (src.isEmpty())) { if ((delimiters.length == 0) || (src.isEmpty())) {
return new String[] {src}; return new String[]{src};
} }
final char[] srcc = src.toCharArray(); final char[] srcc = src.toCharArray();
@ -136,14 +153,14 @@ public class StringUtils {
start[0] = 0; start[0] = 0;
int s = 0, e; int s = 0, e;
if (CharUtil.equalsOne(srcc[0], delimiters)) { // string starts with delimiter if (CharUtil.equalsOne(srcc[0], delimiters)) { // string starts with delimiter
end[0] = 0; end[0] = 0;
count++; count++;
s = CharUtil.findFirstDiff(srcc, 1, delimiters); s = CharUtil.findFirstDiff(srcc, 1, delimiters);
if (s == -1) { // nothing after delimiters if (s == -1) { // nothing after delimiters
return new String[] {EMPTY, EMPTY}; return new String[]{EMPTY, EMPTY};
} }
start[1] = s; // new start start[1] = s; // new start
} }
while (true) { while (true) {
// find new end // find new end
@ -173,7 +190,7 @@ public class StringUtils {
public static String[] splitc(final String src, final char delimiter) { public static String[] splitc(final String src, final char delimiter) {
if (src.isEmpty()) { if (src.isEmpty()) {
return new String[] {EMPTY}; return new String[]{EMPTY};
} }
final char[] srcc = src.toCharArray(); final char[] srcc = src.toCharArray();
@ -185,14 +202,14 @@ public class StringUtils {
start[0] = 0; start[0] = 0;
int s = 0, e; int s = 0, e;
if (srcc[0] == delimiter) { // string starts with delimiter if (srcc[0] == delimiter) { // string starts with delimiter
end[0] = 0; end[0] = 0;
count++; count++;
s = CharUtil.findFirstDiff(srcc, 1, delimiter); s = CharUtil.findFirstDiff(srcc, 1, delimiter);
if (s == -1) { // nothing after delimiters if (s == -1) { // nothing after delimiters
return new String[] {EMPTY, EMPTY}; return new String[]{EMPTY, EMPTY};
} }
start[1] = s; // new start start[1] = s; // new start
} }
while (true) { while (true) {
// find new end // find new end
@ -222,12 +239,13 @@ public class StringUtils {
public static String[] splitc(final String src, final String d) { public static String[] splitc(final String src, final String d) {
if ((d.isEmpty()) || (src.isEmpty())) { if ((d.isEmpty()) || (src.isEmpty())) {
return new String[] {src}; return new String[]{src};
} }
return splitc(src, d.toCharArray()); return splitc(src, d.toCharArray());
} }
public static class MessageFormatter { public static class MessageFormatter {
static final char DELIM_START = '{'; static final char DELIM_START = '{';
static final char DELIM_STOP = '}'; static final char DELIM_STOP = '}';
static final String DELIM_STR = "{}"; static final String DELIM_STR = "{}";
@ -265,7 +283,7 @@ public class StringUtils {
} }
final public static FormattingTuple arrayFormat(final String messagePattern, final Object[] argArray, final public static FormattingTuple arrayFormat(final String messagePattern, final Object[] argArray,
Throwable throwable) { Throwable throwable) {
if (messagePattern == null) { if (messagePattern == null) {
return new FormattingTuple(null, argArray, throwable); return new FormattingTuple(null, argArray, throwable);
@ -559,10 +577,10 @@ public class StringUtils {
return Lists.newArrayList(); return Lists.newArrayList();
} }
return Splitter.on(",").omitEmptyStrings() return Splitter.on(",").omitEmptyStrings()
.trimResults().splitToList(str.trim()) .trimResults().splitToList(str.trim())
.stream() .stream()
.filter(NumberUtils::isDigits) .filter(NumberUtils::isDigits)
.map(Long::parseLong).collect(Collectors.toList()); .map(Long::parseLong).collect(Collectors.toList());
} }
/** /**
@ -573,10 +591,10 @@ public class StringUtils {
return Lists.newArrayList(); return Lists.newArrayList();
} }
return Splitter.on(",").omitEmptyStrings() return Splitter.on(",").omitEmptyStrings()
.trimResults().splitToList(str.trim()) .trimResults().splitToList(str.trim())
.stream() .stream()
.filter(NumberUtils::isDigits) .filter(NumberUtils::isDigits)
.map(Integer::parseInt).collect(Collectors.toList()); .map(Integer::parseInt).collect(Collectors.toList());
} }
/** /**
@ -646,7 +664,7 @@ public class StringUtils {
} }
char c = s.charAt(0); char c = s.charAt(0);
return (c > 0x3130 && c < 0x318F) return (c > 0x3130 && c < 0x318F)
|| (c >= 0xAC00 && c <= 0xD7A3); || (c >= 0xAC00 && c <= 0xD7A3);
} }
/** /**
@ -764,8 +782,7 @@ public class StringUtils {
sb.append(s, c, i); sb.append(s, c, i);
sb.append(with); sb.append(with);
c = i + sub.length(); c = i + sub.length();
} } while ((i = s.indexOf(sub, c)) != -1);
while ((i = s.indexOf(sub, c)) != -1);
if (c < length) { if (c < length) {
sb.append(s, c, length); sb.append(s, c, length);
} }
@ -818,8 +835,8 @@ public class StringUtils {
return name; return name;
} }
if (name.length() > 1 && if (name.length() > 1 &&
Character.isUpperCase(name.charAt(1)) && Character.isUpperCase(name.charAt(1)) &&
Character.isUpperCase(name.charAt(0))) { Character.isUpperCase(name.charAt(0))) {
return name; return name;
} }

View File

@ -1,3 +1,20 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.nebula.base.utils; package com.nebula.base.utils;
import java.io.File; import java.io.File;
@ -21,6 +38,7 @@ public class SystemInfo {
* is forbidden in Android, we will get an exception. * is forbidden in Android, we will get an exception.
*/ */
private static class HostInfoLazy { private static class HostInfoLazy {
private final String HOST_NAME; private final String HOST_NAME;
private final String HOST_ADDRESS; private final String HOST_ADDRESS;
@ -232,7 +250,6 @@ public class SystemInfo {
return packages.toArray(new String[0]); return packages.toArray(new String[0]);
} }
// ---------------------------------------------------------------- java checks // ---------------------------------------------------------------- java checks
private int detectJavaVersionNumber() { private int detectJavaVersionNumber() {
@ -268,7 +285,6 @@ public class SystemInfo {
return JAVA_VERSION_NUMBER == version; return JAVA_VERSION_NUMBER == version;
} }
private final String OS_VERSION = SystemUtil.get("os.version"); private final String OS_VERSION = SystemUtil.get("os.version");
private final String OS_ARCH = SystemUtil.get("os.arch"); private final String OS_ARCH = SystemUtil.get("os.arch");
private final String OS_NAME = SystemUtil.get("os.name"); private final String OS_NAME = SystemUtil.get("os.name");
@ -324,7 +340,6 @@ public class SystemInfo {
} }
} }
public final boolean isAix() { public final boolean isAix() {
return IS_OS_AIX; return IS_OS_AIX;
} }
@ -433,35 +448,35 @@ public class SystemInfo {
/** /**
* Returns MAX memory. * Returns MAX memory.
*/ */
public final long getMaxMemory(){ public final long getMaxMemory() {
return runtime.maxMemory(); return runtime.maxMemory();
} }
/** /**
* Returns TOTAL memory. * Returns TOTAL memory.
*/ */
public final long getTotalMemory(){ public final long getTotalMemory() {
return runtime.totalMemory(); return runtime.totalMemory();
} }
/** /**
* Returns FREE memory. * Returns FREE memory.
*/ */
public final long getFreeMemory(){ public final long getFreeMemory() {
return runtime.freeMemory(); return runtime.freeMemory();
} }
/** /**
* Returns usable memory. * Returns usable memory.
*/ */
public final long getAvailableMemory(){ public final long getAvailableMemory() {
return runtime.maxMemory() - runtime.totalMemory() + runtime.freeMemory(); return runtime.maxMemory() - runtime.totalMemory() + runtime.freeMemory();
} }
/** /**
* Returns used memory. * Returns used memory.
*/ */
public final long getUsedMemory(){ public final long getUsedMemory() {
return runtime.totalMemory() - runtime.freeMemory(); return runtime.totalMemory() - runtime.freeMemory();
} }
@ -481,7 +496,6 @@ public class SystemInfo {
// ---------------------------------------------------------------- user // ---------------------------------------------------------------- user
private final String USER_NAME = SystemUtil.get("user.name"); private final String USER_NAME = SystemUtil.get("user.name");
private final String USER_HOME = nosep(SystemUtil.get("user.home")); private final String USER_HOME = nosep(SystemUtil.get("user.home"));
private final String USER_DIR = nosep(SystemUtil.get("user.dir")); private final String USER_DIR = nosep(SystemUtil.get("user.dir"));

View File

@ -1,3 +1,20 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.nebula.base.utils; package com.nebula.base.utils;
import java.security.AccessController; import java.security.AccessController;

View File

@ -1,3 +1,20 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.nebula.base.utils; package com.nebula.base.utils;
import java.util.concurrent.ThreadFactory; import java.util.concurrent.ThreadFactory;
@ -30,8 +47,7 @@ public class ThreadFactoryImpl implements ThreadFactory {
Thread thread = new Thread(r, threadNamePrefix + this.threadIndex.incrementAndGet()); Thread thread = new Thread(r, threadNamePrefix + this.threadIndex.incrementAndGet());
thread.setDaemon(daemon); thread.setDaemon(daemon);
thread.setUncaughtExceptionHandler((t, e) -> thread.setUncaughtExceptionHandler((t, e) -> log.error("Thread has an uncaught exception, threadId={}, threadName={}",
log.error("Thread has an uncaught exception, threadId={}, threadName={}",
t.getId(), t.getName(), e)); t.getId(), t.getName(), e));
return thread; return thread;

View File

@ -1,3 +1,20 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.nebula.base.utils; package com.nebula.base.utils;
import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.ArrayBlockingQueue;

View File

@ -1,3 +1,20 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.nebula.base.utils; package com.nebula.base.utils;
import java.time.Instant; import java.time.Instant;

View File

@ -1,3 +1,20 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.nebula.base.utils.io; package com.nebula.base.utils.io;
import com.nebula.base.utils.DigestEngine; import com.nebula.base.utils.DigestEngine;
@ -824,7 +841,6 @@ public class FileUtil {
// ---------------------------------------------------------------- stream // ---------------------------------------------------------------- stream
/** /**
* @see #writeStream(File, InputStream) * @see #writeStream(File, InputStream)
*/ */
@ -1224,7 +1240,6 @@ public class FileUtil {
moveFile(src, dest); moveFile(src, dest);
} }
// ---------------------------------------------------------------- smart delete // ---------------------------------------------------------------- smart delete
/** /**
@ -1398,7 +1413,7 @@ public class FileUtil {
while (true) { while (true) {
try { try {
return File.createTempFile(prefix, suffix, tempDir).getCanonicalFile(); return File.createTempFile(prefix, suffix, tempDir).getCanonicalFile();
} catch (final IOException ioex) { // fixes java.io.WinNTFileSystem.createFileExclusively access denied } catch (final IOException ioex) { // fixes java.io.WinNTFileSystem.createFileExclusively access denied
if (++exceptionsCount >= 50) { if (++exceptionsCount >= 50) {
throw ioex; throw ioex;
} }

View File

@ -1,3 +1,20 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.nebula.base.utils.io; package com.nebula.base.utils.io;
import java.io.BufferedInputStream; import java.io.BufferedInputStream;

View File

@ -1,3 +1,20 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.nebula.base.utils.io; package com.nebula.base.utils.io;
import java.io.IOException; import java.io.IOException;
@ -11,7 +28,7 @@ import java.nio.charset.StandardCharsets;
* @date : 2022/1/14 13:55 * @date : 2022/1/14 13:55
* @description: * @description:
*/ */
public class UnicodeInputStream extends InputStream{ public class UnicodeInputStream extends InputStream {
public static final int MAX_BOM_SIZE = 4; public static final int MAX_BOM_SIZE = 4;

View File

@ -1,6 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
@ -11,8 +10,6 @@
<name>spring-boot-nebula-dependencies</name> <name>spring-boot-nebula-dependencies</name>
<description>spring boot 基础组件,快速构建spring boot项目</description> <description>spring boot 基础组件,快速构建spring boot项目</description>
<url>https://github.com/weihubeats/spring-boot-common</url>
<properties> <properties>
<revision>0.0.01</revision> <revision>0.0.01</revision>
@ -29,6 +26,8 @@
<javers-core.version>6.6.5</javers-core.version> <javers-core.version>6.6.5</javers-core.version>
<mybatis-plus-boot-starter.version>3.5.5</mybatis-plus-boot-starter.version> <mybatis-plus-boot-starter.version>3.5.5</mybatis-plus-boot-starter.version>
<redission.version>3.17.3</redission.version> <redission.version>3.17.3</redission.version>
<spotless-maven-plugin.version>2.43.0</spotless-maven-plugin.version>
</properties> </properties>
@ -116,38 +115,10 @@
<version>${redission.version}</version> <version>${redission.version}</version>
</dependency> </dependency>
</dependencies> </dependencies>
</dependencyManagement> </dependencyManagement>
<licenses>
<license>
<name>The Apache Software License, Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
<distribution>repo</distribution>
</license>
</licenses>
<developers>
<developer>
<name>weihubeats</name>
<email>weihu@apche.org</email>
<organization>https://weihubeats.blog.csdn.net/</organization>
</developer>
</developers>
<scm>
<connection>scm:git@github.com:weihubeats/spring-boot-common.git</connection>
<developerConnection>scm:git@github.com:weihubeats/spring-boot-common.git</developerConnection>
<url>git@github.com:weihubeats/spring-boot-common.git</url>
</scm>
<issueManagement>
<system>Github Issue</system>
<url>https://github.com/weihubeats/spring-boot-common/issues</url>
</issueManagement>
<build> <build>
<plugins> <plugins>
<plugin> <plugin>
@ -180,10 +151,10 @@
</configuration> </configuration>
<executions> <executions>
<execution> <execution>
<phase>package</phase>
<goals> <goals>
<goal>jar-no-fork</goal> <goal>jar-no-fork</goal>
</goals> </goals>
<phase>package</phase>
</execution> </execution>
</executions> </executions>
</plugin> </plugin>
@ -205,10 +176,10 @@
</configuration> </configuration>
<executions> <executions>
<execution> <execution>
<phase>package</phase>
<goals> <goals>
<goal>jar</goal> <goal>jar</goal>
</goals> </goals>
<phase>package</phase>
</execution> </execution>
</executions> </executions>
</plugin> </plugin>
@ -220,10 +191,10 @@
<executions> <executions>
<execution> <execution>
<id>sign-artifacts</id> <id>sign-artifacts</id>
<phase>verify</phase>
<goals> <goals>
<goal>sign</goal> <goal>sign</goal>
</goals> </goals>
<phase>verify</phase>
</execution> </execution>
</executions> </executions>
</plugin> </plugin>
@ -239,33 +210,100 @@
<executions> <executions>
<execution> <execution>
<id>flatten</id> <id>flatten</id>
<phase>process-resources</phase>
<goals> <goals>
<goal>flatten</goal> <goal>flatten</goal>
</goals> </goals>
<phase>process-resources</phase>
</execution> </execution>
<execution> <execution>
<id>flatten.clean</id> <id>flatten.clean</id>
<phase>clean</phase>
<goals> <goals>
<goal>clean</goal> <goal>clean</goal>
</goals> </goals>
<phase>clean</phase>
</execution> </execution>
</executions> </executions>
</plugin> </plugin>
<plugin>
<groupId>com.diffplug.spotless</groupId>
<artifactId>spotless-maven-plugin</artifactId>
<version>${spotless-maven-plugin.version}</version>
<configuration>
<java>
<eclipse>
<file>${maven.multiModuleProjectDirectory}/dev-support/spotless_nebula_formatter.xml</file>
</eclipse>
<licenseHeader>
<file>${maven.multiModuleProjectDirectory}/dev-support/license-header</file>
</licenseHeader>
</java>
<pom>
<sortPom>
<encoding>UTF-8</encoding>
<nrOfIndentSpace>4</nrOfIndentSpace>
<keepBlankLines>true</keepBlankLines>
<indentBlankLines>false</indentBlankLines>
<indentSchemaLocation>true</indentSchemaLocation>
<spaceBeforeCloseEmptyElement>true</spaceBeforeCloseEmptyElement>
<sortModules>false</sortModules>
<sortExecutions>false</sortExecutions>
<predefinedSortOrder>custom_1</predefinedSortOrder>
<expandEmptyElements>false</expandEmptyElements>
<sortProperties>false</sortProperties>
</sortPom>
</pom>
</configuration>
<executions>
<execution>
<goals>
<goal>apply</goal>
</goals>
<phase>compile</phase>
</execution>
</executions>
</plugin>
</plugins> </plugins>
</build> </build>
<url>https://github.com/weihubeats/spring-boot-common</url>
<licenses>
<license>
<name>The Apache Software License, Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
<distribution>repo</distribution>
</license>
</licenses>
<developers>
<developer>
<name>weihubeats</name>
<email>weihu@apche.org</email>
<organization>https://weihubeats.blog.csdn.net/</organization>
</developer>
</developers>
<scm>
<connection>scm:git@github.com:weihubeats/spring-boot-common.git</connection>
<developerConnection>scm:git@github.com:weihubeats/spring-boot-common.git</developerConnection>
<url>git@github.com:weihubeats/spring-boot-common.git</url>
</scm>
<issueManagement>
<system>Github Issue</system>
<url>https://github.com/weihubeats/spring-boot-common/issues</url>
</issueManagement>
<distributionManagement> <distributionManagement>
<snapshotRepository>
<id>sonatype</id>
<url>https://s01.oss.sonatype.org/content/repositories/snapshots/</url>
</snapshotRepository>
<repository> <repository>
<id>sonatype</id> <id>sonatype</id>
<url>https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/</url> <url>https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</repository> </repository>
<snapshotRepository>
<id>sonatype</id>
<url>https://s01.oss.sonatype.org/content/repositories/snapshots/</url>
</snapshotRepository>
</distributionManagement> </distributionManagement>
</project> </project>

View File

@ -1,6 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<parent> <parent>

View File

@ -1,3 +1,20 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.nebula.distribute.lock.annotation; package com.nebula.distribute.lock.annotation;
import java.lang.annotation.Documented; import java.lang.annotation.Documented;

View File

@ -1,3 +1,20 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.nebula.distribute.lock.aop; package com.nebula.distribute.lock.aop;
import com.nebula.base.utils.DataUtils; import com.nebula.base.utils.DataUtils;
@ -43,6 +60,7 @@ public class NebulaDistributedLockAnnotationInterceptor implements MethodInterce
boolean fairLock = annotation.fairLock(); boolean fairLock = annotation.fairLock();
if (annotation.tryLock()) { if (annotation.tryLock()) {
return lock.tryLock(new DistributedLock<>() { return lock.tryLock(new DistributedLock<>() {
@Override @Override
public Object process() { public Object process() {
return proceed(methodInvocation); return proceed(methodInvocation);
@ -55,6 +73,7 @@ public class NebulaDistributedLockAnnotationInterceptor implements MethodInterce
}, annotation.tryWaitTime(), annotation.outTime(), annotation.timeUnit(), fairLock); }, annotation.tryWaitTime(), annotation.outTime(), annotation.timeUnit(), fairLock);
} else { } else {
return lock.lock(new DistributedLock<>() { return lock.lock(new DistributedLock<>() {
@Override @Override
public Object process() { public Object process() {
return proceed(methodInvocation); return proceed(methodInvocation);

View File

@ -1,3 +1,20 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.nebula.distribute.lock.autoconfigure; package com.nebula.distribute.lock.autoconfigure;
import com.nebula.aop.base.NebulaBaseAnnotationAdvisor; import com.nebula.aop.base.NebulaBaseAnnotationAdvisor;

View File

@ -1,3 +1,20 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.nebula.distribute.lock.core; package com.nebula.distribute.lock.core;
/** /**

View File

@ -1,3 +1,20 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.nebula.distribute.lock.core; package com.nebula.distribute.lock.core;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -16,7 +33,7 @@ public interface NebulaDistributedLockTemplate {
/** /**
* 默认尝试加锁时间 * 默认尝试加锁时间
*/ */
long DEFAULT_TRY_OUT_TIME = 30; long DEFAULT_TRY_OUT_TIME = 30;
/** /**
* 默认时间单位 * 默认时间单位
*/ */
@ -63,5 +80,4 @@ public interface NebulaDistributedLockTemplate {
*/ */
<T> T tryLock(DistributedLock<T> distributedLock, long tryOutTime, long outTime, TimeUnit timeUnit, boolean fairLock); <T> T tryLock(DistributedLock<T> distributedLock, long tryOutTime, long outTime, TimeUnit timeUnit, boolean fairLock);
} }

View File

@ -1,3 +1,20 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.nebula.distribute.lock.core; package com.nebula.distribute.lock.core;
import com.nebula.distribute.lock.exception.DistributedLockException; import com.nebula.distribute.lock.exception.DistributedLockException;
@ -43,7 +60,7 @@ public class RedissonDistributedLockTemplate implements NebulaDistributedLockTem
@Override @Override
public <T> T tryLock(DistributedLock<T> distributedLock, long tryOutTime, long outTime, TimeUnit timeUnit, public <T> T tryLock(DistributedLock<T> distributedLock, long tryOutTime, long outTime, TimeUnit timeUnit,
boolean fairLock) { boolean fairLock) {
String lockName = distributedLock.lockName(); String lockName = distributedLock.lockName();
RLock lock = getLock(lockName, fairLock); RLock lock = getLock(lockName, fairLock);
try { try {

View File

@ -1,3 +1,20 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.nebula.distribute.lock.exception; package com.nebula.distribute.lock.exception;
/** /**

View File

@ -1,6 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<parent> <parent>

View File

@ -1,3 +1,20 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.nebula.mybatis.entity; package com.nebula.mybatis.entity;
import java.time.LocalDateTime; import java.time.LocalDateTime;

View File

@ -1,3 +1,20 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.nebula.mybatis.handler; package com.nebula.mybatis.handler;
import java.math.BigDecimal; import java.math.BigDecimal;
@ -21,6 +38,7 @@ import org.apache.ibatis.type.TypeException;
@MappedJdbcTypes(JdbcType.ARRAY) @MappedJdbcTypes(JdbcType.ARRAY)
@MappedTypes({Integer[].class, String[].class, Boolean[].class, Double[].class, Long[].class, BigDecimal[].class}) @MappedTypes({Integer[].class, String[].class, Boolean[].class, Double[].class, Long[].class, BigDecimal[].class})
public class ArrayTypeHandler extends BaseTypeHandler<Object[]> { public class ArrayTypeHandler extends BaseTypeHandler<Object[]> {
private static final String TYPE_NAME_VARCHAR = "varchar"; private static final String TYPE_NAME_VARCHAR = "varchar";
private static final String TYPE_NAME_INTEGER = "integer"; private static final String TYPE_NAME_INTEGER = "integer";
private static final String TYPE_NAME_BOOLEAN = "boolean"; private static final String TYPE_NAME_BOOLEAN = "boolean";
@ -29,7 +47,7 @@ public class ArrayTypeHandler extends BaseTypeHandler<Object[]> {
@Override @Override
public void setNonNullParameter( public void setNonNullParameter(
PreparedStatement ps, int i, Object[] parameter, JdbcType jdbcType) throws SQLException { PreparedStatement ps, int i, Object[] parameter, JdbcType jdbcType) throws SQLException {
String typeName = null; String typeName = null;
if (parameter instanceof Integer[]) { if (parameter instanceof Integer[]) {
typeName = TYPE_NAME_INTEGER; typeName = TYPE_NAME_INTEGER;

View File

@ -1,22 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent> <parent>
<artifactId>spring-boot-nebula</artifactId>
<groupId>io.github.weihubeats</groupId> <groupId>io.github.weihubeats</groupId>
<artifactId>spring-boot-nebula</artifactId>
<version>${revision}</version> <version>${revision}</version>
</parent> </parent>
<artifactId>spring-boot-nebula-samples</artifactId>
<packaging>pom</packaging>
<modules> <modules>
<module>spring-boot-nebula-web-sample</module> <module>spring-boot-nebula-web-sample</module>
<module>spring-boot-nebula-distribute-lock-sample</module> <module>spring-boot-nebula-distribute-lock-sample</module>
</modules> </modules>
<modelVersion>4.0.0</modelVersion>
<packaging>pom</packaging>
<artifactId>spring-boot-nebula-samples</artifactId>
<properties> <properties>
<maven.compiler.source>8</maven.compiler.source> <maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target> <maven.compiler.target>8</maven.compiler.target>

View File

@ -1,6 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<parent> <parent>

View File

@ -1,3 +1,20 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.nebula.distribute.lock.sample; package com.nebula.distribute.lock.sample;
import java.util.TimeZone; import java.util.TimeZone;

View File

@ -1,3 +1,20 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.nebula.distribute.lock.sample.config; package com.nebula.distribute.lock.sample.config;
import com.nebula.base.utils.DataUtils; import com.nebula.base.utils.DataUtils;
@ -25,7 +42,6 @@ public class RedissonConfig {
@Value("${redis.password}") @Value("${redis.password}")
private String redisLoginPassword; private String redisLoginPassword;
@Bean @Bean
public RedissonClient redissonClient() { public RedissonClient redissonClient() {
return createRedis(redisLoginHost, redisLoginPort, redisLoginPassword); return createRedis(redisLoginHost, redisLoginPort, redisLoginPassword);

View File

@ -1,3 +1,20 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.nebula.distribute.lock.sample.controller; package com.nebula.distribute.lock.sample.controller;
import com.nebula.distribute.lock.sample.service.TestService; import com.nebula.distribute.lock.sample.service.TestService;
@ -19,10 +36,9 @@ public class TestController {
private final TestService testServcie; private final TestService testServcie;
@GetMapping("/test") @GetMapping("/test")
@NebulaResponseBody @NebulaResponseBody
public String test() throws Exception{ public String test() throws Exception {
testServcie.test(); testServcie.test();
return "小奏"; return "小奏";
} }

View File

@ -1,3 +1,20 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.nebula.distribute.lock.sample.service; package com.nebula.distribute.lock.sample.service;
import com.nebula.distribute.lock.annotation.NebulaDistributedLock; import com.nebula.distribute.lock.annotation.NebulaDistributedLock;

View File

@ -1,3 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>

View File

@ -1,3 +1,20 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.nebula.web.sample; package com.nebula.web.sample;
import java.util.TimeZone; import java.util.TimeZone;

View File

@ -1,3 +1,20 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.nebula.web.sample.controller; package com.nebula.web.sample.controller;
import com.nebula.web.boot.annotation.NebulaResponseBody; import com.nebula.web.boot.annotation.NebulaResponseBody;
@ -14,7 +31,6 @@ import org.springframework.web.bind.annotation.RestController;
@RequestMapping() @RequestMapping()
public class TestController { public class TestController {
@GetMapping("/test") @GetMapping("/test")
@NebulaResponseBody @NebulaResponseBody
public String test() { public String test() {

View File

@ -1,6 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<parent> <parent>
@ -29,6 +28,19 @@
<artifactId>spring-boot-nebula-common</artifactId> <artifactId>spring-boot-nebula-common</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
</dependencies> </dependencies>
</project> </project>

View File

@ -1,3 +1,20 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.nebula.web.common.autoconfigure; package com.nebula.web.common.autoconfigure;
import com.nebula.web.common.utils.NebulaSysWebUtils; import com.nebula.web.common.utils.NebulaSysWebUtils;
@ -19,9 +36,8 @@ public class NebulaWebCommonAutoConfiguration {
} }
@Bean @Bean
public NebulaSysWebUtils nebulaSysWebUtils() { public NebulaSysWebUtils nebulaSysWebUtils() {
return new NebulaSysWebUtils(); return new NebulaSysWebUtils();
} }
} }

View File

@ -1,9 +1,25 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.nebula.web.common.utils; package com.nebula.web.common.utils;
import com.nebula.base.utils.DataUtils; import com.nebula.base.utils.DataUtils;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.Objects; import java.util.Objects;
import org.apache.commons.lang3.StringUtils;
import org.springframework.core.LocalVariableTableParameterNameDiscoverer; import org.springframework.core.LocalVariableTableParameterNameDiscoverer;
import org.springframework.expression.ExpressionParser; import org.springframework.expression.ExpressionParser;
import org.springframework.expression.spel.standard.SpelExpressionParser; import org.springframework.expression.spel.standard.SpelExpressionParser;
@ -28,8 +44,9 @@ public class ExpressionUtil {
if (DataUtils.isEmpty(expressionString)) { if (DataUtils.isEmpty(expressionString)) {
return null; return null;
} }
//获取被拦截方法参数名列表 // 获取被拦截方法参数名列表
LocalVariableTableParameterNameDiscoverer discoverer = new LocalVariableTableParameterNameDiscoverer(); LocalVariableTableParameterNameDiscoverer discoverer = new LocalVariableTableParameterNameDiscoverer();
// SPEL解析
String[] paramNames = discoverer.getParameterNames(method); String[] paramNames = discoverer.getParameterNames(method);
if (paramNames == null || args == null || paramNames.length != args.length) { if (paramNames == null || args == null || paramNames.length != args.length) {
throw new IllegalArgumentException("Method parameter names and argument values do not match."); throw new IllegalArgumentException("Method parameter names and argument values do not match.");

View File

@ -1,3 +1,20 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.nebula.web.common.utils; package com.nebula.web.common.utils;
import java.util.Objects; import java.util.Objects;

View File

@ -1,3 +1,20 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.nebula.web.common.utils; package com.nebula.web.common.utils;
import org.springframework.beans.BeansException; import org.springframework.beans.BeansException;

View File

@ -0,0 +1,53 @@
package com.nebula.web.common.utils;
import com.nebula.web.common.autoconfigure.NebulaWebCommonAutoConfiguration;
import java.util.Objects;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import static org.junit.jupiter.api.Assertions.assertThrowsExactly;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* @author : wh
* @date : 2024/3/28 09:45
* @description:
*/
@SpringBootTest(classes = SpringBeanUtilsTest.TestConfig.class)
public class SpringBeanUtilsTest {
@Test
public void getBean() {
Object bean = SpringBeanUtils.getBean("testBean");
assertTrue(bean instanceof TestBean);
TestBean bean1 = SpringBeanUtils.getBean(TestBean.class);
assertTrue(Objects.nonNull(bean1));
assertThrowsExactly(NoSuchBeanDefinitionException.class, () -> SpringBeanUtils.getBean(NoTestBean.class));
}
static final class TestBean {
}
static final class NoTestBean {
}
@Configuration
@EnableAutoConfiguration
@ImportAutoConfiguration({NebulaWebCommonAutoConfiguration.class})
public static class TestConfig {
@Bean
public TestBean testBean() {
return new TestBean();
}
}
}

View File

@ -1,14 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent> <parent>
<groupId>io.github.weihubeats</groupId> <groupId>io.github.weihubeats</groupId>
<artifactId>spring-boot-nebula</artifactId> <artifactId>spring-boot-nebula</artifactId>
<version>${revision}</version> <version>${revision}</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>spring-boot-nebula-web</artifactId> <artifactId>spring-boot-nebula-web</artifactId>
@ -37,5 +36,4 @@
</dependencies> </dependencies>
</project> </project>

View File

@ -1,3 +1,20 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.nebula.web.boot.annotation; package com.nebula.web.boot.annotation;
import java.lang.annotation.Documented; import java.lang.annotation.Documented;

View File

@ -1,3 +1,20 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.nebula.web.boot.annotation; package com.nebula.web.boot.annotation;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;

View File

@ -1,3 +1,20 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.nebula.web.boot.api; package com.nebula.web.boot.api;
import java.io.Serializable; import java.io.Serializable;

View File

@ -1,3 +1,20 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.nebula.web.boot.api; package com.nebula.web.boot.api;
import java.util.Collection; import java.util.Collection;
@ -76,7 +93,7 @@ public class NebulaPage<T> {
*/ */
public static <T> NebulaPage<T> ofMemory(Collection<T> list, NebulaPageQuery pageQuery) { public static <T> NebulaPage<T> ofMemory(Collection<T> list, NebulaPageQuery pageQuery) {
List<T> pageList = list.stream().skip((long) (pageQuery.getPageIndex() - 1) * pageQuery.getPageSize()) List<T> pageList = list.stream().skip((long) (pageQuery.getPageIndex() - 1) * pageQuery.getPageSize())
.limit(pageQuery.getPageSize()).collect(Collectors.toList()); .limit(pageQuery.getPageSize()).collect(Collectors.toList());
NebulaPage<T> page = new NebulaPage<>(); NebulaPage<T> page = new NebulaPage<>();
page.setList(pageList); page.setList(pageList);
page.setTotalCount(list.size()); page.setTotalCount(list.size());

View File

@ -1,3 +1,20 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.nebula.web.boot.api; package com.nebula.web.boot.api;
/** /**

View File

@ -1,3 +1,20 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.nebula.web.boot.api; package com.nebula.web.boot.api;
import com.nebula.web.boot.enums.ResultCode; import com.nebula.web.boot.enums.ResultCode;
@ -37,7 +54,6 @@ public class NebulaResponse<T> implements Serializable {
*/ */
private String msg; private String msg;
private NebulaResponse(IResultCode resultCode) { private NebulaResponse(IResultCode resultCode) {
this(resultCode, null, resultCode.getMessage()); this(resultCode, null, resultCode.getMessage());
} }
@ -145,7 +161,4 @@ public class NebulaResponse<T> implements Serializable {
return new NebulaResponse<>(ResultCode.FAILURE, msg); return new NebulaResponse<>(ResultCode.FAILURE, msg);
} }
} }

View File

@ -1,3 +1,20 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.nebula.web.boot.config; package com.nebula.web.boot.config;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
@ -28,16 +45,13 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@AllArgsConstructor @AllArgsConstructor
public class BaseWebMvcConfig implements WebMvcConfigurer { public class BaseWebMvcConfig implements WebMvcConfigurer {
private final ObjectMapper objectMapper; private final ObjectMapper objectMapper;
@Override @Override
public void addReturnValueHandlers(List<HandlerMethodReturnValueHandler> returnValueHandlers) { public void addReturnValueHandlers(List<HandlerMethodReturnValueHandler> returnValueHandlers) {
returnValueHandlers.add(new NebulaResponseBodyHandleReturnValue()); returnValueHandlers.add(new NebulaResponseBodyHandleReturnValue());
} }
/** /**
* 使用 JACKSON 作为JSON MessageConverter * 使用 JACKSON 作为JSON MessageConverter
* @param converters * @param converters

View File

@ -1,3 +1,20 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.nebula.web.boot.enums; package com.nebula.web.boot.enums;
import com.nebula.web.boot.api.IResultCode; import com.nebula.web.boot.api.IResultCode;
@ -35,7 +52,6 @@ public enum ResultCode implements IResultCode {
BIZ_EXCEPTION(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "业务异常"); BIZ_EXCEPTION(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "业务异常");
/** /**
* code编码 * code编码
*/ */
@ -45,10 +61,4 @@ public enum ResultCode implements IResultCode {
*/ */
final String message; final String message;
} }

View File

@ -1,3 +1,20 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.nebula.web.boot.error; package com.nebula.web.boot.error;
import com.nebula.web.boot.api.NebulaResponse; import com.nebula.web.boot.api.NebulaResponse;
@ -98,7 +115,7 @@ public class NebulaRestExceptionHandler {
@ExceptionHandler(MethodArgumentTypeMismatchException.class) @ExceptionHandler(MethodArgumentTypeMismatchException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST) @ResponseStatus(HttpStatus.BAD_REQUEST)
public NebulaResponse<?> methodArgumentTypeMismatchException(HttpServletRequest request, public NebulaResponse<?> methodArgumentTypeMismatchException(HttpServletRequest request,
MethodArgumentTypeMismatchException e) { MethodArgumentTypeMismatchException e) {
log.error("参数类型异常 ", e); log.error("参数类型异常 ", e);
return NebulaResponse.fail(ResultCode.PARAM_BIND_ERROR); return NebulaResponse.fail(ResultCode.PARAM_BIND_ERROR);
} }
@ -106,7 +123,7 @@ public class NebulaRestExceptionHandler {
@ExceptionHandler(HttpMessageNotReadableException.class) @ExceptionHandler(HttpMessageNotReadableException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST) @ResponseStatus(HttpStatus.BAD_REQUEST)
public NebulaResponse<?> httpMessageNotReadableExceptionHandle(HttpServletRequest request, public NebulaResponse<?> httpMessageNotReadableExceptionHandle(HttpServletRequest request,
HttpMessageNotReadableException e) { HttpMessageNotReadableException e) {
log.error("数据格式错误 ", e); log.error("数据格式错误 ", e);
return NebulaResponse.fail(ResultCode.PARAM_BIND_ERROR, "数据格式错误"); return NebulaResponse.fail(ResultCode.PARAM_BIND_ERROR, "数据格式错误");
} }
@ -114,7 +131,7 @@ public class NebulaRestExceptionHandler {
@ExceptionHandler(Exception.class) @ExceptionHandler(Exception.class)
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
public NebulaResponse<?> defaultErrorHandle(HttpServletRequest request, HttpServletResponse response, public NebulaResponse<?> defaultErrorHandle(HttpServletRequest request, HttpServletResponse response,
Object handler, Exception ex) { Object handler, Exception ex) {
NebulaResponse<?> baseResponse = new NebulaResponse<>(); NebulaResponse<?> baseResponse = new NebulaResponse<>();
baseResponse.setCode(ResultCode.INTERNAL_SERVER_ERROR.getCode()); baseResponse.setCode(ResultCode.INTERNAL_SERVER_ERROR.getCode());
baseResponse.setMsg("Server busy"); baseResponse.setMsg("Server busy");

View File

@ -1,3 +1,20 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.nebula.web.boot.exception; package com.nebula.web.boot.exception;
import com.nebula.web.boot.api.IResultCode; import com.nebula.web.boot.api.IResultCode;
@ -9,7 +26,8 @@ import lombok.Getter;
* @date : 2023/4/13 10:11 * @date : 2023/4/13 10:11
* @description: * @description:
*/ */
@Getter public abstract class BaseException extends RuntimeException { @Getter
public abstract class BaseException extends RuntimeException {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;

View File

@ -1,3 +1,20 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.nebula.web.boot.exception; package com.nebula.web.boot.exception;
import com.nebula.web.boot.api.IResultCode; import com.nebula.web.boot.api.IResultCode;
@ -12,7 +29,6 @@ public class BizException extends BaseException {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
public BizException(String errMessage) { public BizException(String errMessage) {
super(ResultCode.FAILURE, errMessage); super(ResultCode.FAILURE, errMessage);
} }

View File

@ -1,3 +1,20 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.nebula.web.boot.exception; package com.nebula.web.boot.exception;
/** /**

View File

@ -1,3 +1,20 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.nebula.web.boot.exception; package com.nebula.web.boot.exception;
import com.nebula.web.boot.enums.ResultCode; import com.nebula.web.boot.enums.ResultCode;
@ -8,6 +25,7 @@ import com.nebula.web.boot.enums.ResultCode;
* @description: * @description:
*/ */
public class UnauthorizedException extends BaseException { public class UnauthorizedException extends BaseException {
public UnauthorizedException(String errMessage) { public UnauthorizedException(String errMessage) {
super(ResultCode.UNAUTHORIZED, errMessage); super(ResultCode.UNAUTHORIZED, errMessage);
} }

View File

@ -1,3 +1,20 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.nebula.web.boot.interceptor; package com.nebula.web.boot.interceptor;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
@ -28,7 +45,7 @@ public class NebulaResponseBodyHandleReturnValue implements HandlerMethodReturnV
*/ */
@Override @Override
public boolean supportsReturnType(MethodParameter returnType) { public boolean supportsReturnType(MethodParameter returnType) {
//如果已经是基础的返回值 // 如果已经是基础的返回值
return returnType.getParameterType() != NebulaResponseBody.class return returnType.getParameterType() != NebulaResponseBody.class
&& DataUtils.isNotEmpty(returnType.getAnnotatedElement().getAnnotation(NebulaResponseBody.class)); && DataUtils.isNotEmpty(returnType.getAnnotatedElement().getAnnotation(NebulaResponseBody.class));
} }

View File

@ -1,3 +1,20 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.nebula.web.boot.jackson; package com.nebula.web.boot.jackson;
import com.fasterxml.jackson.core.JsonEncoding; import com.fasterxml.jackson.core.JsonEncoding;
@ -32,6 +49,7 @@ import org.springframework.util.TypeUtils;
* AbstractReadWriteJackson2HttpMessageConverter * AbstractReadWriteJackson2HttpMessageConverter
*/ */
public abstract class AbstractReadWriteJackson2HttpMessageConverter extends AbstractJackson2HttpMessageConverter { public abstract class AbstractReadWriteJackson2HttpMessageConverter extends AbstractJackson2HttpMessageConverter {
private static final java.nio.charset.Charset DEFAULT_CHARSET = Charsets.UTF_8; private static final java.nio.charset.Charset DEFAULT_CHARSET = Charsets.UTF_8;
private final ObjectMapper writeObjectMapper; private final ObjectMapper writeObjectMapper;
@ -76,8 +94,7 @@ public abstract class AbstractReadWriteJackson2HttpMessageConverter extends Abst
} }
@Override @Override
protected void writeInternal(Object object, @Nullable Type type, HttpOutputMessage outputMessage) protected void writeInternal(Object object, @Nullable Type type, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException {
throws IOException, HttpMessageNotWritableException {
MediaType contentType = outputMessage.getHeaders().getContentType(); MediaType contentType = outputMessage.getHeaders().getContentType();
JsonEncoding encoding = getJsonEncoding(contentType); JsonEncoding encoding = getJsonEncoding(contentType);
@ -100,8 +117,7 @@ public abstract class AbstractReadWriteJackson2HttpMessageConverter extends Abst
javaType = getJavaType(type, null); javaType = getJavaType(type, null);
} }
ObjectWriter objectWriter = (serializationView != null ? ObjectWriter objectWriter = (serializationView != null ? this.writeObjectMapper.writerWithView(serializationView) : this.writeObjectMapper.writer());
this.writeObjectMapper.writerWithView(serializationView) : this.writeObjectMapper.writer());
if (filters != null) { if (filters != null) {
objectWriter = objectWriter.with(filters); objectWriter = objectWriter.with(filters);
} }

View File

@ -1,3 +1,20 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.nebula.web.boot.jackson; package com.nebula.web.boot.jackson;
import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonParser;
@ -18,9 +35,10 @@ import java.time.LocalDateTime;
* </> * </>
*/ */
public class LocalDateTimeJacksonDeserializer extends JsonDeserializer<LocalDateTime> { public class LocalDateTimeJacksonDeserializer extends JsonDeserializer<LocalDateTime> {
@Override @Override
public LocalDateTime deserialize( public LocalDateTime deserialize(
JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException { JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
long longValue = jsonParser.getLongValue(); long longValue = jsonParser.getLongValue();
return TimeUtil.toLocalDateTime(longValue); return TimeUtil.toLocalDateTime(longValue);
} }

View File

@ -1,3 +1,20 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.nebula.web.boot.jackson; package com.nebula.web.boot.jackson;
import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.core.JsonGenerator;

View File

@ -1,3 +1,20 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.nebula.web.boot.jackson; package com.nebula.web.boot.jackson;
import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.core.JsonGenerator;

View File

@ -1,3 +1,20 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.nebula.web.boot.resolver; package com.nebula.web.boot.resolver;
import com.nebula.base.utils.DataUtils; import com.nebula.base.utils.DataUtils;
@ -22,62 +39,62 @@ import org.springframework.web.method.support.ModelAndViewContainer;
*/ */
public class TimestampArgumentResolver implements HandlerMethodArgumentResolver { public class TimestampArgumentResolver implements HandlerMethodArgumentResolver {
@Override @Override
public boolean supportsParameter(MethodParameter methodParameter) { public boolean supportsParameter(MethodParameter methodParameter) {
return methodParameter.hasParameterAnnotation(GetTimestamp.class); return methodParameter.hasParameterAnnotation(GetTimestamp.class);
} }
@Override @Override
public Object resolveArgument(MethodParameter methodParameter, ModelAndViewContainer modelAndViewContainer, NativeWebRequest nativeWebRequest, WebDataBinderFactory webDataBinderFactory) throws Exception { public Object resolveArgument(MethodParameter methodParameter, ModelAndViewContainer modelAndViewContainer, NativeWebRequest nativeWebRequest,
GetTimestamp getTimestamp = methodParameter.getParameterAnnotation(GetTimestamp.class); WebDataBinderFactory webDataBinderFactory) throws Exception {
Object instance = methodParameter.getParameterType().getDeclaredConstructor().newInstance(); GetTimestamp getTimestamp = methodParameter.getParameterAnnotation(GetTimestamp.class);
String name = getTimestamp.name(); Object instance = methodParameter.getParameterType().getDeclaredConstructor().newInstance();
if (DataUtils.isEmpty(name)) { String name = getTimestamp.name();
name = methodParameter.getParameterName(); if (DataUtils.isEmpty(name)) {
} name = methodParameter.getParameterName();
if (instance instanceof LocalDateTime) { }
assert name != null; if (instance instanceof LocalDateTime) {
String parameter = nativeWebRequest.getParameter(name); assert name != null;
return parse(parameter); String parameter = nativeWebRequest.getParameter(name);
} return parse(parameter);
}
WebDataBinder binder = webDataBinderFactory.createBinder(nativeWebRequest, instance, name); WebDataBinder binder = webDataBinderFactory.createBinder(nativeWebRequest, instance, name);
binder.registerCustomEditor(LocalDateTime.class, new LocalDateTimeEditor()); binder.registerCustomEditor(LocalDateTime.class, new LocalDateTimeEditor());
ServletRequestParameterPropertyValues propertyValues = new ServletRequestParameterPropertyValues(Objects.requireNonNull(nativeWebRequest.getNativeRequest(ServletRequest.class))); ServletRequestParameterPropertyValues propertyValues = new ServletRequestParameterPropertyValues(Objects.requireNonNull(nativeWebRequest.getNativeRequest(ServletRequest.class)));
binder.bind(propertyValues); binder.bind(propertyValues);
return instance; return instance;
} }
class LocalDateTimeEditor extends PropertyEditorSupport { class LocalDateTimeEditor extends PropertyEditorSupport {
@Override
public String getAsText() {
final LocalDateTime localDateTime = (LocalDateTime) getValue();
if (localDateTime == null) {
return "";
}
return localDateTime.toString();
}
@Override @Override
public void setAsText(String text) throws IllegalArgumentException { public String getAsText() {
setValue(parse(text)); final LocalDateTime localDateTime = (LocalDateTime) getValue();
} if (localDateTime == null) {
} return "";
}
private LocalDateTime parse(String timestampStr) { return localDateTime.toString();
if (DataUtils.isEmpty(timestampStr)) { }
return null;
}
timestampStr = timestampStr.replaceAll("\"", "");
long timestamp = Long.parseLong(timestampStr);
if (timestamp == 0) {
return null;
}
return TimeUtil.toLocalDateTime(timestamp);
}
@Override
public void setAsText(String text) throws IllegalArgumentException {
setValue(parse(text));
}
}
private LocalDateTime parse(String timestampStr) {
if (DataUtils.isEmpty(timestampStr)) {
return null;
}
timestampStr = timestampStr.replaceAll("\"", "");
long timestamp = Long.parseLong(timestampStr);
if (timestamp == 0) {
return null;
}
return TimeUtil.toLocalDateTime(timestamp);
}
} }

View File

@ -1,3 +1,20 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.junit.jupiter.MockitoExtension; import org.mockito.junit.jupiter.MockitoExtension;

View File

@ -1,3 +1,20 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.nebula.web.boot.api; package com.nebula.web.boot.api;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;