TableUtil.java 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package jnpf.base.util.dbutil;
  2. import jnpf.database.constant.DbConst;
  3. import java.util.Random;
  4. /**
  5. * 表字段相关工具类
  6. *
  7. * @author JNPF开发平台组 YanYu
  8. * @version V3.3
  9. * @copyright 引迈信息技术有限公司
  10. * @date 2022-06-08
  11. */
  12. public class TableUtil {
  13. /**
  14. * 随机生成包含大小写字母及数字的字符串
  15. *
  16. * @param length
  17. * @return
  18. */
  19. public static String getStringRandom(int length) {
  20. String val = "";
  21. Random random = new Random();
  22. //参数length,表示生成几位随机数
  23. for (int i = 0; i < length; i++) {
  24. String charOrNum = random.nextInt(2) % 2 == 0 ? "char" : "num";
  25. //输出字母还是数字
  26. if ("char".equalsIgnoreCase(charOrNum)) {
  27. //输出是大写字母还是小写字母
  28. int temp = random.nextInt(2) % 2 == 0 ? 65 : 97;
  29. val += (char) (random.nextInt(26) + temp);
  30. } else if ("num".equalsIgnoreCase(charOrNum)) {
  31. val += String.valueOf(random.nextInt(10));
  32. }
  33. }
  34. return val;
  35. }
  36. /**
  37. * 检测自带表
  38. *
  39. * @param tableName 表明
  40. * @return ignore
  41. */
  42. public static Boolean checkByoTable(String tableName) {
  43. String[] tables = DbConst.BYO_TABLE.split(",");
  44. boolean exists;
  45. for (String table : tables) {
  46. exists = tableName.toLowerCase().equals(table);
  47. if (exists) {
  48. return true;
  49. }
  50. }
  51. return false;
  52. }
  53. }