本页目录
JMockData Github地址:https://github.com/jsonzou/jmockdata
<dependency>
<groupId>com.github.jsonzou</groupId>
<artifactId>jmockdata</artifactId>
<version>4.3.0</version>
<scope>compile</scope>
</dependency>
@Data
public class CommonNameQuantityVO {
private String communityName;
private Integer processes;
private Date date;
}
public static void main(String[] args) {
CommonNameQuantityVO mock = JMockData.mock(CommonNameQuantityVO.class);
System.out.println(mock);
}
CommonNameQuantityVO(communityName=aPMCA, processes=2974, date=Fri Dec 24 16:37:38 CST 2060)
private String QQEmail;
private String zhangsanPhone;
public static void main(String[] args) {
MockConfig mockConfig = new MockConfig()
.subConfig("*ate") // 指定字段名(忽略大小写)以ate结尾的数据范围控制
.doubleRange(80.00, 100.00d) // double BigDecimal
.floatRange(0.00f, 100.00f) // float
.dateRange("2023-01-01", "2023-01-02")
.globalConfig()
// 手机号生成注意正则支持有限,不支持中文,
.subConfig(CommonNameQuantityVO.class, "*tel", "*phone")
.stringRegex("1[3]{1}[0-9]{2}[0-9]{8}")
.globalConfig()
// 指定某个对象的邮箱
.subConfig(CommonNameQuantityVO.class, "QQEmail")
//.stringRegex("[a-z0-9]{5,15}\\@\\w{3,5}\\.[a-z]{2,3}")
.stringRegex("[a-z0-9]{5,15}\\@\\w{3,5}\\.com")
.globalConfig()
// subConfig返回对象是 DataConfig 需要调用globalConfig()才能继续配置其他字段,如果没指定字段则以全局为准
.intRange(30, 60) // int范围
.decimalScale(2); // 保留2位小数点,默认是2位
CommonNameQuantityVO mock = JMockData.mock(CommonNameQuantityVO.class, mockConfig);
System.out.println(mock);
CommonNameQuantityVO(communityName=mDKGSS, processes=30, date=Sun Jan 01 10:38:31 CST 2023, QQEmail=x15d7devedomf@Jd1.com, zhangsanPhone=130975739346)
特殊说明: 以上文章,均是我实际操作,写出来的笔记资料,不会盗用别人文章!烦请各位,请勿直接盗用!转载记得标注来源!