diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/util/StringUtil.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/util/StringUtil.java index 87317fce..87ba1a5d 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/util/StringUtil.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/util/StringUtil.java @@ -16,7 +16,10 @@ package com.mybatisflex.core.util; +import com.mybatisflex.core.exception.FlexExceptions; + import java.util.Collection; +import java.util.Locale; import java.util.function.Function; import java.util.regex.Pattern; @@ -25,6 +28,23 @@ public class StringUtil { private StringUtil() { } + /** + * @see org.apache.ibatis.reflection.property.PropertyNamer#methodToProperty(String) + */ + public static String methodToProperty(String name) { + if (name.startsWith("is")) { + name = name.substring(2); + } else if (name.startsWith("get") || name.startsWith("set")) { + name = name.substring(3); + } else { + throw FlexExceptions.wrap("Error parsing property name '%s'. Didn't start with 'is', 'get' or 'set'.", name); + } + if (!name.isEmpty()) { + name = name.substring(0, 1).toLowerCase(Locale.ENGLISH).concat(name.substring(1)); + } + return name; + } + /** * 第一个字符转换为小写