1>先安裝java8的庫澈吨,jdk8u181-x64.dmg
官網(wǎng)或者 https://www.cr173.com/mac/122803.html
惹是java庫高于java8矩欠,就會出現(xiàn)類似錯誤
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文件夾中
同時在當前文件夾新建json文件
使用終端新建單個命令: touch global.json
全部接口用單個文件配置的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"?
}?
]?
單個文件配置(就是所有接口和返回數(shù)據(jù)全部在一個json文件里面)
java -jar moco-runner-0.10.2-standalone.jar start -p 1234 -c??global.json(端口自己自定義米酬,不要有沖突)?
這個時候就已經(jīng)啟動了接口服務器
重點介紹多個單json文件配置
4>
同樣可以在FilServiceApi文件下 終端新建josn文件:
touch ?config.json
[?
{?
"include": "login/login_request.json"?
},?
{?
"include": "register/register_request.json"?
}?
]?
同時新建文件夾
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": "向右運動",?
"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?
}?
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": "我是注冊接口返回數(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?
}?
全局文件配置(就是接口和返回數(shù)據(jù)分散在不同的json文件里面)
java -jar moco-runner-0.10.2-standalone.jar start -p 1235 -g??config.json?
這個時候查看接口是否正常
http://localhost:1235/test/login?username=admin&password=123456
http://localhost:1235/test/register?username=admin&password=123456
最后參考網(wǎng)址?
http://www.reibang.com/p/0aa0ba7ded5d
http://www.reibang.com/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