Back-end interface
@PostMapping(value = "/run",produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@ResponseBody
public HttpResult triggerJob(@RequestBody JobReceiver jobReceiver) {
//验证值不为空
Preconditions.checkNotNull(jobReceiver.getId(), "Id不能为空");
......
}
Front-end interface to call
runJob = () => {
let params = {
id : this.state.Id,
receiver:''
}
axios.post(`/service/job/run`,params).then( res => {
if(res.code == 200 ){
message.success(res.msg)
}
}).catch( err => {
if(err.response){
message.error(err.response.data.message)
}else if(err.request){
console.log(err.request)
}else{
console.log('Error' , err.message)
}
this.noRunJob()
})
}
axios request fails, the error message and acquires the status code returned backend interface, the processing in the catch
Use tape requestBody in the post request postman
Wherein the rear end of the path request interface path, Body fill in the request parameter, select a raw, then the JSON format data, the input parameters in the interface object below to request succeeds.
In use request command curl
curl -X POST "http://ip:port/job/run" -H "accept: application/json;charset=UTF-8" -H "Content-Type: application/json" -d "{ \"id\": 1, \"receiver\": \"zhengxucheng\"}"
Body request in request body curl mode is "accept: application / json; charset = UTF-8"
Request parameter -d "{\" id \ ": 1, \" receiver \ ": \" zhengxucheng \ "}"