1>先安裝java8的庫,jdk8u181-x64.dmg
官網(wǎng)或者 https://www.cr173.com/mac/122803.html
惹是java庫高于java8,就會(huì)出現(xiàn)類似錯(cuò)誤
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.apache.ibatis.reflection.Reflector(file:/C:/Users/jiangcy/.m2/repository/org/mybatis/mybatis/3.4.5/mybatis-3.4.5.jar)to method java.lang.Object.finalize()?
WARNING: Please consider reporting this to the maintainers of org.apache.ibatis.reflection.Reflector
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
2>
下載 moco-runner-0.10.2-standalone.jar
參考
https://repo1.maven.org/maven2/com/github/dreamhead/moco-runner/
我使用的是0.10.2,直接下載地址是
3>
在任意位置創(chuàng)建文件夾,我命名FilServiceApi,然后將下載的moco-runner-0.10.2-standalone.jar ?放入FilServiceApi文件夾中
同時(shí)在當(dāng)前文件夾新建json文件
使用終端新建單個(gè)命令: touch global.json
全部接口用單個(gè)文件配置的json
[?
{?
"request": {?
"method" : "get",?
"uri": "/getMethod"?
},?
"response": {?
"text": "This is a Get Method!"?
}?
},?
{?
"request": {?
"method" : "get",?
"uri": "/moveToRight"?
},?
"response": {?
"text": "This is a moveToRight Method!"?
}?
},?
{?
"request": {?
"uri": "/getMethodWithParams",?
"queries": {?
"param1": "1",?
"param2": "2"?
}?
},?
"response": {?
"text": "This is a moveToRight Method!"?
}?
},?
{?
"request": {?
"method" : "post",?
"uri": "/postMethod",?
"headers" : {?
"content-type" : "application/json",?
"sessionid": "e566288ba77de98d"?
},?
"forms" :{?
"name" : "admin",?
"password" : "123456"?
}?
},?
"response": {?
"text": "This is a POST Method!"?
}?
},?
{?
"response" : {?
"headers" : {?
"foo" : "bar"?
}?
},?
"include": "blah.json"?
}?
]?
單個(gè)文件配置(就是所有接口和返回?cái)?shù)據(jù)全部在一個(gè)json文件里面)
java -jar moco-runner-0.10.2-standalone.jar start -p 1234 -c??global.json(端口自己自定義,不要有沖突)?
這個(gè)時(shí)候就已經(jīng)啟動(dòng)了接口服務(wù)器
重點(diǎn)介紹多個(gè)單json文件配置
4>
同樣可以在FilServiceApi文件下 終端新建josn文件:
touch ?config.json
[?
{?
"include": "login/login_request.json"?
},?
{?
"include": "register/register_request.json"?
}?
]?
同時(shí)新建文件夾

login文件夾(登陸接口)

login_request.json
[ { "request": {?
"uri": "/test/login",?
"method": "get",?
"queries": {?
"username": "admin",?
"password": "123456"?
} },?
"response": {?
"file": "login/login_response.json"?
} } ]?
login_response.json
{?
"HttpStatus": 200,?
"HttpData": {?
"code": 200,?
"message": null,?
"data":[?
{?
"sta_n": 1,?
"equip_no": 5640,?
"set_no": 4,?
"set_nm": "向右運(yùn)動(dòng)",?
"set_type": "X",?
"main_instruction": "4",?
"minor_instruction": "-",?
"record": true,?
"action": "登陸設(shè)置",?
"value": null,?
"canexecution": true,?
"VoiceKeys": null,?
"EnableVoice": false,?
"Reserve1": null,?
"Reserve2": null,?
"Reserve3": null,?
"qr_equip_no": 0?
}?
]?
},?
"HttpMessage": null?
}?

register文件夾(注冊接口)
register_request.json
[?
{?
"request": {?
"uri": "/test/register",?
"method": "get",?
"queries": {?
"username": "admin",?
"password": "123456"?
}?
},?
"response": {?
"file": "register/register_response.json"?
}?
}?
]?
register_response.json
{?
"HttpStatus": 200,?
"HttpData": {?
"code": 200,?
"message": null,?
"data":[?
{?
"sta_n": 1,?
"equip_no": 5640,?
"set_no": 4,?
"set_nm": "我是注冊接口返回?cái)?shù)據(jù)",?
"set_type": "X",?
"main_instruction": "4",?
"minor_instruction": "-",?
"record": true,?
"action": "注冊",?
"value": null,?
"canexecution": true,?
"VoiceKeys": null,?
"EnableVoice": false,?
"Reserve1": null,?
"Reserve2": null,?
"Reserve3": null,?
"qr_equip_no": 0?
}?
]?
},?
"HttpMessage": null?
}?
全局文件配置(就是接口和返回?cái)?shù)據(jù)分散在不同的json文件里面)
java -jar moco-runner-0.10.2-standalone.jar start -p 1235 -g??config.json?
這個(gè)時(shí)候查看接口是否正常
http://localhost:1235/test/login?username=admin&password=123456
http://localhost:1235/test/register?username=admin&password=123456
最后參考網(wǎng)址?
http://www.itdecent.cn/p/0aa0ba7ded5d
http://www.itdecent.cn/p/638da64422a0
https://blog.csdn.net/shensky711/article/details/52770686#如何在配置文件添加注釋?
使用npm全局安裝json-server:
npm install -g json-server
可以通過查看版本號,來測試是否安裝成功:
json-server -v
json-server --watch db.json