1.什么是mocker.js?
前端可通过执行mocker.js得到想要的模型数据(造数据的过程)
2.mocker.js语法
freemark生成mocker.js(产生随机的数据)
let Mock=require('mockjs');//引入mockjs模块
let Random = Mock.Random;
module.exports = function() {
var data = {//定义等下要返回的json数据
news: []
};
data.news.push({
<#list table.columns as column>
<#if (column.columnNameLower == 'id')>${column.columnNameLower}: Random.id(),
<#elseif (column.javaType == 'String')>${column.columnNameLower}: Random.cword(2,5),
<#elseif (column.javaType == 'Boolean' || column.javaType == 'boolean')>${column.columnNameLower}:Random.boolean(),
<#elseif (column.javaType == 'Integer' || column.javaType == 'int' || column.javaType == 'Long' || column.javaType == 'long')>${column.columnNameLower}: Random.integer(100,5000),
<#elseif (column.javaType == 'Float' || column.javaType == 'float' || column.javaType == 'Double' || column.javaType == 'double')>${column.columnNameLower}: Random.float(0, 100000, 0, 2),
<#elseif (column.javaType == 'Date')>${column.columnNameLower}: Random.date('yyyy-MM-dd'),</#if>
</#list>
})
return data;
}
freemark+mocker的基本语法