Browse Source

纯大写命名,转为小写属性

青苗 9 years ago
parent
commit
88be5f1fc4

+ 13 - 0
mybatis-plus/src/main/java/com/baomidou/mybatisplus/generator/AutoGenerator.java

@@ -453,6 +453,19 @@ public class AutoGenerator {
 	 * @return
 	 */
 	protected String processField(String field) {
+		/*
+		 * 驼峰命名直接返回
+		 */
+		if (!field.contains("_")) {
+			if (StringUtils.isUpperCase(field)) {
+				/*
+				 * 纯大写命名,转为小写属性
+				 */
+				return field.toLowerCase();
+			}
+			return field;
+		}
+
 		/*
 		 * 处理下划线分割命名字段
 		 */

+ 39 - 0
mybatis-plus/src/main/java/com/baomidou/mybatisplus/toolkit/StringUtils.java

@@ -15,6 +15,9 @@
  */
 package com.baomidou.mybatisplus.toolkit;
 
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
 /**
  * <p>
  * String 工具类
@@ -31,7 +34,9 @@ public class StringUtils {
 	public static final char UNDERLINE = '_';
 
 	/**
+	 * <p>
 	 * 判断字符串是否为空
+	 * </p>
 	 *
 	 * @param str
 	 *            需要判断字符串
@@ -42,7 +47,9 @@ public class StringUtils {
 	}
 
 	/**
+	 * <p>
 	 * 判断字符串是否不为空
+	 * </p>
 	 *
 	 * @param str
 	 *            需要判断字符串
@@ -78,7 +85,9 @@ public class StringUtils {
 	}
 
 	/**
+	 * <p>
 	 * 字符串下划线转驼峰格式
+	 * </p>
 	 *
 	 * @param param
 	 *            需要转换的字符串
@@ -102,4 +111,34 @@ public class StringUtils {
 		}
 		return sb.toString();
 	}
+
+	/**
+	 * <p>
+	 * 判断字符串是否为纯大写字母
+	 * </p>
+	 * 
+	 * @param str
+	 *            要匹配的字符串
+	 * @return
+	 */
+	public static boolean isUpperCase(String str) {
+		return match("^[A-Z]+$", str);
+	}
+
+	/**
+	 * <p>
+	 * 正则表达式匹配
+	 * </p>
+	 * 
+	 * @param regex
+	 *            正则表达式字符串
+	 * @param str
+	 *            要匹配的字符串
+	 * @return 如果str 符合 regex的正则表达式格式,返回true, 否则返回 false;
+	 */
+	public static boolean match(String regex, String str) {
+		Pattern pattern = Pattern.compile(regex);
+		Matcher matcher = pattern.matcher(str);
+		return matcher.matches();
+	}
 }