mirror of
https://gitee.com/best_handsome/mybatis-plus-join
synced 2025-07-11 00:02:22 +08:00
update maven plugin
This commit is contained in:
parent
ae6116ce95
commit
5269f3a535
@ -18,12 +18,17 @@ import java.lang.annotation.Target;
|
||||
* <li>加APT后缀并且大写 %SAPT</li>
|
||||
* </ul>
|
||||
* <p>
|
||||
* 支持Ognl语法字段说明<br/>
|
||||
* 支持Ognl语法,字段说明<br/>
|
||||
* Ognl上下文
|
||||
* <ul>
|
||||
* <li>className 类名</li>
|
||||
* <li>classPackage 包名</li>
|
||||
* <li>util 工具类 stringHelper {@link com.github.yulichang.apt.OgnlRoot.StringHelper}</li>
|
||||
* <li>
|
||||
* util 工具类 OgnlUtil {@link com.github.yulichang.processor.utils.OgnlUtil} ,
|
||||
* <a href="https://github.com/yulichang/mybatis-plus-join/tree/master/plugin/mybatis-plus-join-processor/src/main/java/com/github/yulichang/processor/utils/OgnlUtil.java">
|
||||
* github link
|
||||
* </a>
|
||||
* </li>
|
||||
* </ul>
|
||||
* 指定开头 Ognl# 这不是ognl语法,这是MPJ规定的 用于区分 ognl还是String.format
|
||||
* <p>
|
||||
|
@ -1,89 +0,0 @@
|
||||
package com.github.yulichang.extension.apt.matedata;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* apt ognl表达式上下文
|
||||
*
|
||||
* @author yulichang
|
||||
* @since 1.5.0
|
||||
*/
|
||||
@Getter
|
||||
public class OgnlRoot {
|
||||
|
||||
/**
|
||||
* 类名
|
||||
*/
|
||||
private final String className;
|
||||
|
||||
/**
|
||||
* 包名
|
||||
*/
|
||||
private final String classPackage;
|
||||
|
||||
private final StringHelper util = new StringHelper();
|
||||
|
||||
public OgnlRoot(String className, String classPackage) {
|
||||
this.className = className;
|
||||
this.classPackage = classPackage;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public static final class StringHelper {
|
||||
/**
|
||||
* 移除后缀
|
||||
*
|
||||
* @param str 原字符串
|
||||
* @param suffix 指定后缀
|
||||
*/
|
||||
public String removeSuffix(String str, String suffix) {
|
||||
if (isBlank(str) || isBlank(suffix)) {
|
||||
return str;
|
||||
}
|
||||
if (str.endsWith(suffix)) {
|
||||
return str.substring(0, str.length() - suffix.length());
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
/**
|
||||
* 替换后缀
|
||||
*
|
||||
* @param str 原字符串
|
||||
* @param suffix 指定后缀
|
||||
* @param replacement 新后缀
|
||||
*/
|
||||
public String replaceSuffix(String str, String suffix, String replacement) {
|
||||
if (isBlank(str)) {
|
||||
return str;
|
||||
}
|
||||
String rep = Objects.isNull(replacement) ? "" : replacement;
|
||||
if (isBlank(suffix)) {
|
||||
return str + rep;
|
||||
}
|
||||
if (str.endsWith(suffix)) {
|
||||
return str.substring(0, str.length() - suffix.length()) + rep;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取上级包名
|
||||
*
|
||||
* @param pk 报名
|
||||
* @return 上级报名
|
||||
*/
|
||||
public String getParentPackage(String pk) {
|
||||
if (pk.lastIndexOf(".") > -1) {
|
||||
return pk;
|
||||
}
|
||||
return pk.substring(0, pk.lastIndexOf('.'));
|
||||
}
|
||||
|
||||
private boolean isBlank(String str) {
|
||||
return str == null || str.trim().isEmpty();
|
||||
}
|
||||
}
|
||||
}
|
@ -34,11 +34,29 @@
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-core</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.github.yulichang</groupId>
|
||||
<artifactId>mybatis-plus-join-processor</artifactId>
|
||||
<version>${revision}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.13.0</version>
|
||||
<configuration>
|
||||
<annotationProcessorPaths>
|
||||
<path>
|
||||
<groupId>com.github.yulichang</groupId>
|
||||
<artifactId>mybatis-plus-join-processor</artifactId>
|
||||
<version>${revision}</version>
|
||||
</path>
|
||||
<path>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.34</version>
|
||||
</path>
|
||||
</annotationProcessorPaths>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
|
@ -16,14 +16,17 @@
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.github.yulichang</groupId>
|
||||
<artifactId>mybatis-plus-join-core</artifactId>
|
||||
<version>${revision}</version>
|
||||
<groupId>ognl</groupId>
|
||||
<artifactId>ognl</artifactId>
|
||||
<version>3.4.3</version>
|
||||
<scope>compile</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-extension</artifactId>
|
||||
<version>${mpj.mybatis.plus.version}</version>
|
||||
<groupId>org.javassist</groupId>
|
||||
<artifactId>javassist</artifactId>
|
||||
<version>3.30.2-GA</version>
|
||||
<scope>compile</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
@ -48,6 +51,7 @@
|
||||
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.13.0</version>
|
||||
<configuration>
|
||||
@ -56,6 +60,74 @@
|
||||
<target>1.8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.6.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
<phase>package</phase>
|
||||
<configuration>
|
||||
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||
<createSourcesJar>true</createSourcesJar>
|
||||
<artifactSet>
|
||||
<includes>
|
||||
<include>ognl:ognl</include>
|
||||
<include>org.javassist:javassist</include>
|
||||
</includes>
|
||||
</artifactSet>
|
||||
<filters>
|
||||
<filter>
|
||||
<artifact>ognl:ognl</artifact>
|
||||
<excludes>
|
||||
<exclude>META-INF/MANIFEST.MF</exclude>
|
||||
</excludes>
|
||||
</filter>
|
||||
<filter>
|
||||
<artifact>org.javassist:javassist</artifact>
|
||||
<excludes>
|
||||
<exclude>META-INF/MANIFEST.MF</exclude>
|
||||
</excludes>
|
||||
</filter>
|
||||
</filters>
|
||||
<relocations>
|
||||
<relocation>
|
||||
<pattern>ognl</pattern>
|
||||
<shadedPattern>com.github.yulichang.processor.ognl</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>javassist</pattern>
|
||||
<shadedPattern>com.github.yulichang.processor.javassist</shadedPattern>
|
||||
</relocation>
|
||||
</relocations>
|
||||
<shadeSourcesContent>true</shadeSourcesContent>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-site-plugin</artifactId>
|
||||
<version>4.0.0-M14</version>
|
||||
<configuration>
|
||||
<locales>default,es,ja,fr,zh_CN,ko</locales>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.jacoco</groupId>
|
||||
<artifactId>jacoco-maven-plugin</artifactId>
|
||||
<version>0.8.12</version>
|
||||
<configuration>
|
||||
<excludes>
|
||||
<exclude>com.github.yulichang.processor.ognl.*</exclude>
|
||||
<exclude>com.github.yulichang.processor.javassist.*</exclude>
|
||||
</excludes>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
@ -1,9 +1,5 @@
|
||||
package com.github.yulichang.processor;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.github.yulichang.annotation.Table;
|
||||
import com.github.yulichang.extension.apt.matedata.BaseColumn;
|
||||
import com.github.yulichang.extension.apt.matedata.Column;
|
||||
import com.github.yulichang.processor.matedata.Conf;
|
||||
import com.github.yulichang.processor.matedata.FieldInfo;
|
||||
import com.github.yulichang.processor.matedata.TableInfo;
|
||||
@ -31,6 +27,13 @@ import java.util.stream.Collectors;
|
||||
*/
|
||||
public class EntityProcessor extends AbstractProcessor {
|
||||
|
||||
private static final String TABLE = "com.github.yulichang.annotation.Table";
|
||||
private static final String TABLE_FIELD = "com.baomidou.mybatisplus.annotation.TableField";
|
||||
private static final String TABLE_FIELD_EXIST = "exist";
|
||||
|
||||
private static final String BASE_COLUMN = "com.github.yulichang.extension.apt.matedata.BaseColumn";
|
||||
private static final String COLUMN = "com.github.yulichang.extension.apt.matedata.Column";
|
||||
|
||||
private Elements elementUtils;
|
||||
private Types typeUtils;
|
||||
private Messager messager;
|
||||
@ -53,7 +56,7 @@ public class EntityProcessor extends AbstractProcessor {
|
||||
@Override
|
||||
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
|
||||
if (!roundEnv.processingOver()) {
|
||||
TypeElement table = annotations.stream().filter(i -> i.toString().equals(Table.class.getName())).findFirst().orElse(null);
|
||||
TypeElement table = annotations.stream().filter(i -> i.toString().equals(TABLE)).findFirst().orElse(null);
|
||||
if (table != null) {
|
||||
note("mybatis plus join processor start");
|
||||
Set<? extends Element> tables = roundEnv.getElementsAnnotatedWith(table);
|
||||
@ -71,7 +74,7 @@ public class EntityProcessor extends AbstractProcessor {
|
||||
@Override
|
||||
public Set<String> getSupportedAnnotationTypes() {
|
||||
Set<String> supportedAnnotationTypes = new HashSet<>();
|
||||
supportedAnnotationTypes.add(Table.class.getCanonicalName());
|
||||
supportedAnnotationTypes.add(TABLE);
|
||||
return supportedAnnotationTypes;
|
||||
}
|
||||
|
||||
@ -85,19 +88,16 @@ public class EntityProcessor extends AbstractProcessor {
|
||||
*/
|
||||
private TableInfo createColumn(TypeElement element) {
|
||||
AnnotationMirror tb = element.getAnnotationMirrors().stream().filter(a ->
|
||||
a.getAnnotationType().asElement().toString().equals(Table.class.getName())).findFirst().orElse(null);
|
||||
Table table = element.getAnnotation(Table.class);
|
||||
a.getAnnotationType().asElement().toString().equals(TABLE)).findFirst().orElse(null);
|
||||
if (tb == null) {
|
||||
return null;
|
||||
}
|
||||
Set<String> keySet = tb.getElementValues().keySet().stream().map(k ->
|
||||
k.getSimpleName().toString()).collect(Collectors.toSet());
|
||||
Conf conf = Conf.getConf(globalConf, table, keySet);
|
||||
Conf conf = Conf.getConf(globalConf, tb.getElementValues());
|
||||
TableInfo tableInfo = new TableInfo(conf, element.toString(), element.getSimpleName().toString());
|
||||
tableInfo.setClassPackage(elementUtils.getPackageOf(element).getQualifiedName().toString());
|
||||
tableInfo.setClassComment(elementUtils.getDocComment(element));
|
||||
|
||||
Set<FieldInfo> fieldInfos = new HashSet<>();
|
||||
List<FieldInfo> fieldInfos = new ArrayList<>();
|
||||
|
||||
TypeElement currElement = element;
|
||||
do {
|
||||
@ -106,8 +106,15 @@ public class EntityProcessor extends AbstractProcessor {
|
||||
e.getKind() == ElementKind.FIELD && !e.getModifiers().contains(Modifier.STATIC))
|
||||
.filter(e -> {
|
||||
// 过滤 exist = false 的字段
|
||||
TableField tableField = e.getAnnotation(TableField.class);
|
||||
return tableField == null || tableField.exist();
|
||||
AnnotationMirror tableField = e.getAnnotationMirrors().stream().filter(f ->
|
||||
TABLE_FIELD.equals(f.getAnnotationType().toString())).findFirst().orElse(null);
|
||||
if (tableField != null) {
|
||||
Map<String, Object> propMap = tableField.getElementValues().entrySet().stream()
|
||||
.collect(Collectors.toMap(entry -> entry.getKey().getSimpleName().toString(), entry -> entry.getValue().getValue()));
|
||||
Object exist = propMap.get(TABLE_FIELD_EXIST);
|
||||
return exist == null || (boolean) exist;
|
||||
}
|
||||
return true;
|
||||
})
|
||||
.map(e -> new FieldInfo(e.toString(), elementUtils.getDocComment(e))).collect(Collectors.toList()));
|
||||
currElement = (TypeElement) typeUtils.asElement(currElement.getSuperclass());
|
||||
@ -118,8 +125,8 @@ public class EntityProcessor extends AbstractProcessor {
|
||||
StringBuilderHelper content = new StringBuilderHelper(tableInfo)
|
||||
.addPackage(tableInfo.getTagClassPackage())
|
||||
.newLine()
|
||||
.addImport(true, BaseColumn.class.getName())
|
||||
.addImport(true, Column.class.getName())
|
||||
.addImport(true, BASE_COLUMN)
|
||||
.addImport(true, COLUMN)
|
||||
.addImport(true, tableInfo.getClassName())
|
||||
.newLine(tableInfo.isCache())
|
||||
.addImport(tableInfo.isCache(), Map.class.getName())
|
||||
@ -127,7 +134,7 @@ public class EntityProcessor extends AbstractProcessor {
|
||||
.addImport(tableInfo.isCache(), ConcurrentHashMap.class.getName())
|
||||
.newLine()
|
||||
.addClass(tableInfo.getClassComment(), tableInfo.getTagClassName(),
|
||||
BaseColumn.class.getSimpleName() + "<" + tableInfo.getSimpleClassName() + ">",
|
||||
StringUtil.getSimpleName(BASE_COLUMN) + "<" + tableInfo.getSimpleClassName() + ">",
|
||||
c -> c
|
||||
.addConstructor()
|
||||
.addFields()
|
||||
|
@ -1,19 +1,18 @@
|
||||
package com.github.yulichang.processor.matedata;
|
||||
|
||||
import com.github.yulichang.annotation.Table;
|
||||
|
||||
import javax.annotation.processing.Filer;
|
||||
import javax.lang.model.element.AnnotationValue;
|
||||
import javax.lang.model.element.ExecutableElement;
|
||||
import javax.tools.FileObject;
|
||||
import javax.tools.StandardLocation;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
|
||||
public class Conf {
|
||||
|
||||
@ -78,12 +77,12 @@ public class Conf {
|
||||
this.cache = Boolean.parseBoolean(properties.getOrDefault("cache", this.cache).toString());
|
||||
}
|
||||
|
||||
public static Conf getConf(Conf globalConf, Table table, Collection<String> keys) {
|
||||
if (keys == null || keys.isEmpty()) {
|
||||
public static Conf getConf(Conf globalConf, Map<? extends ExecutableElement, ? extends AnnotationValue> elementMap) {
|
||||
if (elementMap == null || elementMap.isEmpty()) {
|
||||
return globalConf;
|
||||
}
|
||||
Conf conf = new Conf(globalConf);
|
||||
keys.forEach(key -> ConfItem.doIt(conf, key, table));
|
||||
elementMap.forEach((k, v) -> ConfItem.doIt(conf, k.getSimpleName().toString(), v));
|
||||
return conf;
|
||||
}
|
||||
|
||||
@ -136,28 +135,25 @@ public class Conf {
|
||||
}
|
||||
|
||||
public enum ConfItem {
|
||||
className("value", Table::value, (c, v) -> c.setClassName(v.toString())),
|
||||
packageName("classPackage", Table::classPackage, (c, v) -> c.setClassPackage(v.toString())),
|
||||
genTables("genTables", Table::genTables, (c, v) -> c.setGenTables((boolean) v)),
|
||||
tablasPackageName("tablesClassPackage", Table::tablesClassPackage, (c, v) -> c.setTablasClassPackage(v.toString())),
|
||||
tablesName("tablesClassName", Table::tablesClassName, (c, v) -> c.setTablesClassName(v.toString())),
|
||||
cache("cache", Table::cache, (c, v) -> c.setCache((boolean) v));
|
||||
className("value", (c, v) -> c.setClassName(v.toString())),
|
||||
packageName("classPackage", (c, v) -> c.setClassPackage(v.toString())),
|
||||
genTables("genTables", (c, v) -> c.setGenTables((boolean) v)),
|
||||
tablasPackageName("tablesClassPackage", (c, v) -> c.setTablasClassPackage(v.toString())),
|
||||
tablesName("tablesClassName", (c, v) -> c.setTablesClassName(v.toString())),
|
||||
cache("cache", (c, v) -> c.setCache((boolean) v));
|
||||
|
||||
private final String action;
|
||||
|
||||
private final Function<Table, Object> annoVal;
|
||||
|
||||
private final BiConsumer<Conf, Object> doIt;
|
||||
|
||||
ConfItem(String action, Function<Table, Object> annoVal, BiConsumer<Conf, Object> doIt) {
|
||||
ConfItem(String action, BiConsumer<Conf, Object> doIt) {
|
||||
this.action = action;
|
||||
this.annoVal = annoVal;
|
||||
this.doIt = doIt;
|
||||
}
|
||||
|
||||
public static void doIt(Conf tableConf, String act, Table anno) {
|
||||
Arrays.stream(ConfItem.values()).filter(f -> f.action.equals(act)).findFirst()
|
||||
.ifPresent(item -> item.doIt.accept(tableConf, item.annoVal.apply(anno)));
|
||||
public static void doIt(Conf tableConf, String key, AnnotationValue value) {
|
||||
Arrays.stream(ConfItem.values()).filter(f -> f.action.equals(key)).findFirst()
|
||||
.ifPresent(item -> item.doIt.accept(tableConf, value.getValue()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,42 @@
|
||||
package com.github.yulichang.processor.matedata;
|
||||
|
||||
import com.github.yulichang.processor.utils.OgnlUtil;
|
||||
|
||||
/**
|
||||
* apt ognl表达式上下文
|
||||
*
|
||||
* @author yulichang
|
||||
* @since 1.5.0
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public class OgnlRoot {
|
||||
|
||||
/**
|
||||
* 类名
|
||||
*/
|
||||
private final String className;
|
||||
|
||||
/**
|
||||
* 包名
|
||||
*/
|
||||
private final String classPackage;
|
||||
|
||||
private final static OgnlUtil util = new OgnlUtil();
|
||||
|
||||
public OgnlRoot(String className, String classPackage) {
|
||||
this.className = className;
|
||||
this.classPackage = classPackage;
|
||||
}
|
||||
|
||||
public String getClassName() {
|
||||
return className;
|
||||
}
|
||||
|
||||
public String getClassPackage() {
|
||||
return classPackage;
|
||||
}
|
||||
|
||||
public OgnlUtil getUtil() {
|
||||
return util;
|
||||
}
|
||||
}
|
@ -1,12 +1,10 @@
|
||||
package com.github.yulichang.processor.matedata;
|
||||
|
||||
import com.github.yulichang.extension.apt.matedata.OgnlRoot;
|
||||
import org.apache.ibatis.builder.BuilderException;
|
||||
import org.apache.ibatis.ognl.Ognl;
|
||||
import org.apache.ibatis.ognl.OgnlContext;
|
||||
import org.apache.ibatis.ognl.OgnlException;
|
||||
import ognl.Ognl;
|
||||
import ognl.OgnlContext;
|
||||
import ognl.OgnlException;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author yulichang
|
||||
@ -28,7 +26,7 @@ public class TableInfo {
|
||||
|
||||
private final Conf conf;
|
||||
|
||||
private Set<FieldInfo> fields;
|
||||
private List<FieldInfo> fields;
|
||||
|
||||
private String tagClassName;
|
||||
private String tagPackageName;
|
||||
@ -90,7 +88,7 @@ public class TableInfo {
|
||||
try {
|
||||
return Ognl.getValue(ognl, context, context.getRoot()).toString();
|
||||
} catch (OgnlException e) {
|
||||
throw new BuilderException("Error evaluating expression '" + ognl + "'. Cause: " + e, e);
|
||||
throw new RuntimeException("Error evaluating expression '" + ognl + "'. Cause: " + e, e);
|
||||
}
|
||||
} else {
|
||||
tag = String.format(expression, source);
|
||||
@ -130,11 +128,11 @@ public class TableInfo {
|
||||
return this.conf.isCache();
|
||||
}
|
||||
|
||||
public Set<FieldInfo> getFields() {
|
||||
public List<FieldInfo> getFields() {
|
||||
return fields;
|
||||
}
|
||||
|
||||
public void setFields(Set<FieldInfo> fields) {
|
||||
public void setFields(List<FieldInfo> fields) {
|
||||
this.fields = fields;
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,60 @@
|
||||
package com.github.yulichang.processor.utils;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public final class OgnlUtil {
|
||||
/**
|
||||
* 移除后缀
|
||||
*
|
||||
* @param str 原字符串
|
||||
* @param suffix 指定后缀
|
||||
*/
|
||||
public String removeSuffix(String str, String suffix) {
|
||||
if (isBlank(str) || isBlank(suffix)) {
|
||||
return str;
|
||||
}
|
||||
if (str.endsWith(suffix)) {
|
||||
return str.substring(0, str.length() - suffix.length());
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
/**
|
||||
* 替换后缀
|
||||
*
|
||||
* @param str 原字符串
|
||||
* @param suffix 指定后缀
|
||||
* @param replacement 新后缀
|
||||
*/
|
||||
public String replaceSuffix(String str, String suffix, String replacement) {
|
||||
if (isBlank(str)) {
|
||||
return str;
|
||||
}
|
||||
String rep = Objects.isNull(replacement) ? "" : replacement;
|
||||
if (isBlank(suffix)) {
|
||||
return str + rep;
|
||||
}
|
||||
if (str.endsWith(suffix)) {
|
||||
return str.substring(0, str.length() - suffix.length()) + rep;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取上级包名
|
||||
*
|
||||
* @param pk 报名
|
||||
* @return 上级报名
|
||||
*/
|
||||
public String getParentPackage(String pk) {
|
||||
if (pk.lastIndexOf(".") > -1) {
|
||||
return pk;
|
||||
}
|
||||
return pk.substring(0, pk.lastIndexOf('.'));
|
||||
}
|
||||
|
||||
private boolean isBlank(String str) {
|
||||
return str == null || str.trim().isEmpty();
|
||||
}
|
||||
}
|
@ -9,4 +9,11 @@ public final class StringUtil {
|
||||
public static boolean isNotEmpty(String str) {
|
||||
return !isEmpty(str);
|
||||
}
|
||||
|
||||
public static String getSimpleName(String fullName) {
|
||||
if (isEmpty(fullName) && fullName.lastIndexOf(".") == -1) {
|
||||
return fullName;
|
||||
}
|
||||
return fullName.substring(fullName.lastIndexOf(".") + 1);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user