Easy mock学习

1.Easy mock官网进行注册登陆java

2.建立我的项目小程序

 

3.建立接口 预览接口api

 

 引入mock.js 返回值支持随机生成 数组

语法列子1:dom

{
"success": true,
"data": {
"projects|3-10": [{   //在3到10之间随机取数
"name": "演示用",
"url": "@url",  //随机生成URL地址
"email": "@email", //随机生成邮箱
"address": "@county(true)",//随机生成地址
"string|1-10": "★", //字符随机递增1到10个
"number|1-100": 100,//取1到100的随机数
"boolean|1-2": true,//随机取布尔值
"object|2": { //在数组里面随机输出两个
"310000": "上海市",
"320000": "江苏省",
"330000": "浙江省"
}
}]
}
}测试

 语法列子2:url

{
"resultCode": 999999,
"resultMessage": "success",
"data": {

"productList": () => {
var productList = [{
"productId": "1161102724370108419aaaaaaaaaaaaa",
"brand": "阿迪达斯Adidas",
"tagPrice": 21800,
"category": "男益生菌/初乳",
"picture": ["http://devdevnew.oss.aikucun.com/21529a91bb71f55ff0c447181c24c5acc6e91430_1564472487604_92.jpg", "http://devdevnew.oss.aikucun.com/2dfc8caa93a1a23dd0bc420bc58c8ecf8f3497b6_1564472487612_83.jpg", "http://devdevnew.oss.aikucun.com/1c8ca7e3766331e5837b84d6e4a7369809e32dee_1564472487594_84.jpg", "http://devdevnew.oss.aikucun.com/ca54bf096bf96ac4d91436a4323f407f126673fd_1564472487585_62.jpg"],
"brandSizeUrl": "http://devdevnew.oss.aikucun.com/ca54bf096bf96ac4d91436a4323f407f126673fd_1564472487585_62.jpg",
"price": 13000,
"name": "商户云移动版测试商品【辅食/白的/市场价218】",
"settlementPrice": 12000,
"profit": 1000,
"skusAttributeList": [{
"attributeName": "尺码",
"attributeValue": "20"
}, {
"attributeName": "颜色",
"attributeValue": "白的"
}],
"skuList": [{
"skuId": "1161102724370108419aaaaaaaaaaaaa",
"attributeList": [{
"attributeName": "颜色",
"attributeValue": "白的"
}, {
"attributeName": "尺码",
"attributeValue": "20"
}]
}],
"description": "2600三、 阿迪达斯Adidas男益生菌/初乳-¥130.00\n尺码 20 \n款式 商户云移动版测试商品【辅食/白的/市场价218】\n款号 989524",
"weight": "20.0",
"volume": "20.0"
}, {
"productId": "1161102724370108419aaaaaaaaaaaaa",
"brand": "阿迪达斯Adidas",
"tagPrice": 21801,
"category": "男益生菌/初乳",
"picture": ["http://devdevnew.oss.aikucun.com/21529a91bb71f55ff0c447181c24c5acc6e91430_1564472487604_92.jpg", "http://devdevnew.oss.aikucun.com/2dfc8caa93a1a23dd0bc420bc58c8ecf8f3497b6_1564472487612_83.jpg", "http://devdevnew.oss.aikucun.com/1c8ca7e3766331e5837b84d6e4a7369809e32dee_1564472487594_84.jpg", "http://devdevnew.oss.aikucun.com/ca54bf096bf96ac4d91436a4323f407f126673fd_1564472487585_62.jpg"],
"brandSizeUrl": "http://devdevnew.oss.aikucun.com/ca54bf096bf96ac4d91436a4323f407f126673fd_1564472487585_62.jpg",
"price": 13000,
"name": "商户云移动版测试商品【辅食/白的/市场价218】",
"settlementPrice": 12000,
"profit": 1000,
"skusAttributeList": [{
"attributeName": "尺码",
"attributeValue": "20"
}, {
"attributeName": "颜色",
"attributeValue": "白的"
}],
"skuList": [{
"skuId": "1161102724370108419aaaaaaaaaaaaa",
"attributeList": [{
"attributeName": "颜色",
"attributeValue": "白的"
}, {
"attributeName": "尺码",
"attributeValue": "20"
}]
}],
"description": "2600三、 阿迪达斯Adidas男益生菌/初乳-¥130.00\n尺码 20 \n款式 商户云移动版测试商品【辅食/白的/市场价218】\n款号 989524",
"weight": "20.0",
"volume": "20.0"
}, {
"productId": "1161102724370108419aaaaaaaaaaaaa",
"brand": "阿迪达斯Adidas",
"tagPrice": 21802,
"category": "男益生菌/初乳",
"picture": ["http://devdevnew.oss.aikucun.com/21529a91bb71f55ff0c447181c24c5acc6e91430_1564472487604_92.jpg", "http://devdevnew.oss.aikucun.com/2dfc8caa93a1a23dd0bc420bc58c8ecf8f3497b6_1564472487612_83.jpg", "http://devdevnew.oss.aikucun.com/1c8ca7e3766331e5837b84d6e4a7369809e32dee_1564472487594_84.jpg", "http://devdevnew.oss.aikucun.com/ca54bf096bf96ac4d91436a4323f407f126673fd_1564472487585_62.jpg"],
"brandSizeUrl": "http://devdevnew.oss.aikucun.com/ca54bf096bf96ac4d91436a4323f407f126673fd_1564472487585_62.jpg",
"price": 13000,
"name": "商户云移动版测试商品【辅食/白的/市场价218】",
"settlementPrice": 12000,
"profit": 1000,
"skusAttributeList|0": [{
"attributeName": "尺码",
"attributeValue": "20"
}, {
"attributeName": "颜色",
"attributeValue": "白的"
}],
"skuList": [{
"skuId": "1161102724370108419aaaaaaaaaaaaa",
"attributeList": [{
"attributeName": "颜色",
"attributeValue": "白的"
}, {
"attributeName": "尺码",
"attributeValue": "20"
}]
}],
"description": "2600三、 阿迪达斯Adidas男益生菌/初乳-¥130.00\n尺码 20 \n款式 商户云移动版测试商品【辅食/白的/市场价218】\n款号 989524",
"weight": "20.0",
"volume": "20.0"
}]
let size = 2

let pSize = productList.length
if (pSize < size) {
size = pSize
}
// let size = Math.ceil(Math.random() * size)
let start = Math.floor(Math.random() * pSize)
let end = start + size
if (end >= pSize) {
end = pSize
start = pSize - size
}
return productList.slice(start, end)
}
}

}3d

 

 

4.java项目中使用easy mock blog

将相关项目配置文件中修改openapi配置地址,改为本身mock的地址接口

5. 本地搭建easy mock 待补充

6. easy mock在小程序中的应用 待补充

相关文章
相关标签/搜索