public class MockUtil extends Object
随机数据助手,可能会用到的所有随机方法
此类所有的方法,只要在方法名前加上'@' 即可在Mock中作为映射指令
例如:
map.put("name" , "@cname");
map.put("age" , "@age");
map.put("place" , "@ctitle(2,5)");
※以下列表仅供参考,一切以方法内实际参数为准,此注释有些情况可能未及时更新。
--名称、title等相关
cname()
获取一个中文姓名
cnames(Integer, Integer)
获取指定数量区间[min , max]个随机中文名
cnames(Integer)
获取指定数量个随机中文名
name()
获取一个英文姓名
names(Integer, Integer)
获取指定数量区间[min, max]个随机英文姓名
names(Integer)
获取指定数量num个随机英文姓名
ctitle()
获取一段中文,3-5
ctitle(Integer)
获取一段指定长度的中文
ctitle(Integer)
获取指定数量区间个随机汉字,区间[min,max]
title()
获取一段指定长度的英文5-10
title(Integer)
获取一段指定长度的英文
title(Integer)
获取指定数量区间个随机英文,区间[min,max]
UUID()
获取一个UUID
--date相关
date()
获取随机日期 1990 - 现在
toDateStr()
返回一个日随机日期的字符串
time(String)
返回一个随机时间的字符串
time()
返回一个随机时间的字符串,格式为HH:mm:ss
toDateTime(String)
返回一个随机时间日期的字符串
toDateTime()
返回一个随机日期时间的字符串,格式为yyyy-dd-MM HH:mm:ss
--number相关
age()
获取一个随机年龄 12-80
integer()
获取随机数字 0-9
integer(Integer)
获取指定长度的随机数,※不可超过int最大上限
integer(Integer, Integer)
获取指定区间[a,b]的随机数,※不可超过int最大上限
doubles(Integer, Integer, Integer, Integer)
获取指定区间[a,b]的小数,指定小数位数[endL,endR],double类型
doubles(Integer, Integer, Integer)
获取指定区间[a,b]的小数,指定小数位数[end],double类型
doubles(Integer, Integer)
获取指定区间[a,b]的小数,默认小数位数为0,double类型
doubles(Integer)
获取指定数值为a的小数,默认小数位数为0,double类型
UUNUM()
获取一个32位的随机数字
getNumber(Integer)
获取任意长度的随机整数
getDouble(Integer, Integer)
获取指定位的小数
getDouble(Integer, Integer, Integer, Integer)
获取指定位的小数
UUDOUBLE()
获取32位小数,小数为2位
--String character相关
bool()
返回一个随机布尔值
bool(double)
根据概率返回布尔值
--String character相关
character()
获取一个随机字符
MockUtil#character(Character[]...)
在提供的字符字典(数组中)随机 返回
word(Integer)
返回一个随机的假单词,指定长度区间[min,max]
word(Integer, Integer)
返回一个随机的假单词,指定长度
word()
返回一个随机的假单词
cword(Integer)
返回一个随机的假中文词语,指定长度区间[min,max]
cword(Integer)
返回一个随机的假中文词语,指定长度
cword()
返回一个随机的假中文词语
--color相关
color()
获取一个随机颜色的16进制代码
--text相关
sentence(Integer, Integer)
随机假英文句子,句子中的单词数量为参数的区间[min,max]
sentence(Integer)
返回指定长度的句子
sentence()
返回长度为12-18长度的句子
csentence(Integer, Integer)
随机假中文句子,句子中的单词数量为参数的区间[min,max]
csentence(Integer)
返回指定长度的中文句子
csentence()
返回长度为5-10长度的中文句子
paragraph(Integer, Integer)
返回一个文本,文中句子数量为参数区间[min,max]
paragraph(Integer)
返回指定句子数量的文本
paragraph()
返回一个有3-7个句子的文本
cparagraph(Integer, Integer)
返回一个文本,文中句子数量为参数区间[min,max]
cparagraph(Integer)
返回指定句子数量的文本
cparagraph()
返回一个有3-7个句子的文本
--web相关
ip()
获取一个随机IP
tId()
获取一个随机的顶级域名
email(String, String)
返回一个随机邮箱,可以指定邮箱的名称(@后面的名字)和顶级域名
email(String)
返回一个随机邮箱,可以指定邮箱的名称(@后面的名字)
email()
返回一个随机邮箱
domain(String)
随机生成一个域名,可指定顶级域名
domain()
随机生成一个域名
url(String)
随机一个url路径,可指定域名
url()
随机一个url
Modifier and Type | Method and Description |
---|---|
static Integer |
age()
获取一个随机年龄
12 - 80
|
static Boolean |
bool()
返回一个随机布尔值
|
static Boolean |
bool(double prob)
根据概率返回布尔值
|
static String |
cfirstName()
随机获取一个中文姓氏 - 百家姓中获取
|
static Character |
character()
获取一个随机字符
|
static Character |
character(Character[]... dic)
在提供的字典(数组中)随机 返回
|
static String |
cname()
获取一个随机中文名称
|
static String[] |
cnames(Integer num)
获取指定数量个随机中文名
|
static String[] |
cnames(Integer min,
Integer max)
获取指定数量区间[min , max]个随机中文名
|
static String |
color()
获取一个随机颜色的16进制代码
|
static String |
cparagraph()
返回一个有3-7个句子的文本
|
static String |
cparagraph(Integer length)
返回指定句子数量的文本
|
static String |
cparagraph(Integer min,
Integer max)
返回一个文本,文中句子数量为参数区间[min,max]
|
static String |
csentence()
返回长度为5-10长度的中文句子
|
static String |
csentence(Integer length)
返回指定长度的中文句子
|
static String |
csentence(Integer min,
Integer max)
随机假中文句子,句子中的单词数量为参数的区间[min,max]
|
static String |
ctitle()
获取3-5个随机汉字
|
static String |
ctitle(Integer num)
获取指定数量个随机汉字
|
static String |
ctitle(Integer min,
Integer max)
获取指定数量区间个随机汉字,区间[min,max]
|
static String |
cword()
返回一个随机的假中文词语,长度2-4
|
static String |
cword(Integer length)
返回一个随机的假中文词语,指定长度
|
static String |
cword(Integer min,
Integer max)
返回一个随机的假中文词语,指定长度区间[min,max]
|
static Date |
date()
获取随机日期
时间:1990 - 现在
|
static String |
domain()
随机生成一个域名
|
static String |
domain(String tid)
随机生成一个域名,可指定顶级域名
|
static Double |
doubles(Integer a)
获取指定数值为a的小数,默认小数位数为0,double类型
|
static Double |
doubles(Integer a,
Integer b)
获取指定区间[a,b]的小数,默认小数位数为0,double类型
|
static Double |
doubles(Integer a,
Integer b,
Integer end)
获取指定区间[a,b]的小数,指定小数位数[end],double类型
|
static Double |
doubles(Integer a,
Integer b,
Integer endL,
Integer endR)
获取制定区间[a,b]的小数,指定小数位数[endL,endR],double类型
|
static String |
email()
返回一个随机邮箱
|
static String |
email(String emailName)
返回一个随机邮箱,可以指定邮箱的名称(@后面的名字)
|
static String |
email(String emailName,
String tid)
返回一个随机邮箱,可以指定邮箱的名称(@后面的名字)和顶级域名
|
static String |
getDouble(Integer intLength,
Integer douLength)
获取指定位的小数
|
static String |
getDouble(Integer intMinLength,
Integer intMaxLength,
Integer douMinLength,
Integer douMaxLength)
获取指定位的小数的最大区间
|
static String |
getNumber(Integer length)
获取任意长度的随机整数
|
static String |
getNumber(Integer min,
Integer max)
获取任意长度的随机整数
|
static Integer |
integer()
获取随机数字
0-9
|
static Integer |
integer(Integer length)
获取指定长度的随机数
|
static Integer |
integer(Integer a,
Integer b)
获取指定区间[a,b]的随机数
|
static String |
ip()
获取一个随机IP
|
static String |
name()
获取一个随机英文姓名-两个开头大写的英文字母(title(2,7)+" "+title(2,7))
|
static String[] |
names(Integer num)
获取指定数量num个随机英文姓名
|
static String[] |
names(Integer min,
Integer max)
获取指定数量区间[min, max]个随机英文姓名
|
static String |
paragraph()
返回一个有3-7个句子的文本
|
static String |
paragraph(Integer length)
返回指定句子数量的文本
|
static String |
paragraph(Integer min,
Integer max)
返回一个文本,文中句子数量为参数区间[min,max]
|
static String |
sentence()
返回长度为12-18长度的句子
|
static String |
sentence(Integer length)
返回指定长度的句子
|
static String |
sentence(Integer min,
Integer max)
随机假英文句子,句子中的单词数量为参数的区间[min,max]
|
static String |
string()
获取5-10长度的英文字符串,纯小写
|
static String |
string(Integer num)
获取指定长度的英文字符串,纯小写
|
static String |
string(Integer min,
Integer max)
获取指定长度的英文字符串,纯小写
|
static String |
stringUpper()
获取5-10长度的英文字符串,纯大写
|
static String |
stringUpper(Integer num)
获取指定长度的英文字符串,纯大写
|
static String |
stringUpper(Integer min,
Integer max)
获取指定长度的英文字符串,纯大写
|
static String |
tId()
获取一个随机的顶级域名
|
static String |
time()
返回一个随机时间的字符串,格式为HH:mm:ss
|
static String |
time(String format)
返回一个随机时间的字符串
|
static String |
title()
获取5-10长度的英文字符串,开头大写
|
static String |
title(Integer num)
获取指定长度的英文字符串,开头大写
|
static String |
title(Integer min,
Integer max)
获取指定长度的英文字符串,开头大写
|
static String |
toDateStr()
返回一个随机日期的字符串,格式为yyyy-dd-MM
|
static String |
toDateStr(String format)
返回一个随机日期的字符串
|
static String |
toDateTime()
返回一个随机日期时间的字符串,格式为yyyy-dd-MM HH:mm:ss
|
static String |
toDateTime(String format)
返回一个随机时间日期的字符串
|
static String |
url()
随机一个url
|
static String |
url(String domainName)
随机一个url路径,可指定域名
|
static String |
UUDOUBLE()
获取32位小数,小数为2位
|
static String |
UUID()
获取一个UUID
|
static String |
UUNUM()
获取一个32位的随机数字
|
static String |
word()
返回一个随机的假单词
|
static String |
word(Integer length)
返回一个随机的假单词,指定长度
|
static String |
word(Integer min,
Integer max)
返回一个随机的假单词,指定长度区间[min,max]
|
public static String cname()
public static String[] cnames(Integer min, Integer max)
min
- 最小数量max
- 最大数量public static String cfirstName()
public static String name()
public static String[] names(Integer min, Integer max)
min
- 最少数量max
- 最大数量public static String ctitle()
public static String ctitle(Integer min, Integer max)
min
- 最少数量max
- 最大数量public static String title()
public static String title(Integer min, Integer max)
min
- 最小长度max
- 最大长度public static String string(Integer min, Integer max)
min
- 最小长度max
- 最大长度public static String string()
public static String stringUpper(Integer min, Integer max)
min
- 最小长度max
- 最大长度public static String stringUpper()
public static String UUID()
public static Date date()
public static String toDateStr()
public static String time()
public static String toDateTime()
public static Integer age()
public static Integer integer()
public static Integer integer(Integer length)
length
- 长度,长度请不要超过整数型上限。getNumber(Integer)
public static Integer integer(Integer a, Integer b)
a
- 最小值b
- 最大值public static Double doubles(Integer a, Integer b, Integer endL, Integer endR)
a
- 整数部分的最小值b
- 整数部分的最大值endL
- 小数部分位数最小值endR
- 小数部分位数最大值public static Double doubles(Integer a, Integer b, Integer end)
a
- b
- end
- public static Double doubles(Integer a, Integer b)
a
- b
- public static Double doubles(Integer a)
a
- public static String UUNUM()
public static String getNumber(Integer min, Integer max)
min
- 最小长度max
- 最大长度public static String getDouble(Integer intLength, Integer douLength)
intLength
- 整数部分的长度douLength
- 保留小数位数public static String getDouble(Integer intMinLength, Integer intMaxLength, Integer douMinLength, Integer douMaxLength)
intMinLength
- 整数部分的长度最小值intMaxLength
- 整数部分的长度最大值douMinLength
- 保留小数位数最小值douMaxLength
- 保留小数位数最大值public static String UUDOUBLE()
public static Character character()
public static String word()
public static String word(Integer min, Integer max)
min
- 最小长度max
- 最大长度public static String cword(Integer min, Integer max)
min
- 最小长度max
- 最大长度public static String cword()
public static String color()
public static Boolean bool()
public static Boolean bool(double prob)
prob
- 返回true的概率,建议取值区间:0-1public static String sentence(Integer min, Integer max)
min
- 单词最少数量max
- 单词最多数量public static String sentence()
public static String csentence(Integer min, Integer max)
min
- 单词最少数量max
- 单词最多数量public static String csentence()
public static String paragraph(Integer min, Integer max)
min
- max
- public static String paragraph()
public static String cparagraph(Integer min, Integer max)
min
- 最小数量max
- 最大数量public static String cparagraph()
public static String ip()
public static String tId()
public static String email()
public static String domain()
public static String url()
Copyright © 2024. All rights reserved.