RESTful风格接口与axios请求总结
1.GET
axios.get('/api/patient/ds', {
params: {
pageNo: a,
pageCount: b,
name: app.hzQuery.name,
age: app.hzQuery.age
}
}).then(function (response) {
console.log(response);
app.yyArr = response.data.data.records;
app.stuTotal = response.data.data.total;
})
@GetMapping("ds")
@ApiOperation("展示患者信息")
public Result listPatients(Integer pageNo, Integer pageCount, String name, String age) {
log.info("展示患者信息");
PatientQuery patientQuery = new PatientQuery();
patientQuery.setPageCount(pageCount);
patientQuery.setPageNo(pageNo);
patientQuery.setName(name);
patientQuery.setAge(age);
return patientService.listPatients(patientQuery);
}
axios.get("/api/dot/getYs/" + id)
.then(function (response) {
app.staffInfo = response.data.data;
app.showUpdate = true;
app.$refs["yuyueInfo"].resetFields();
})
@GetMapping("getYs/{id}")
@ApiOperation("根据ID查询医生信息")
public Result getDoctorById(@PathVariable("id") Integer id) {
log.info("获取id,{}", id);
return doctorService.getDoctorById(id);
}
2.POST
axios.post('/api/patient/add', app.stuInfo).then(function (response) {
console.log(response);
app.showAdd = false;
app.$notify.info({title: '提示', message: response.data.msg});
getStuInfo(1, 10);
})
@PostMapping("add")
@ApiOperation("添加患者")
@OpetionLog("添加患者")
public Result addPatient(@RequestBody PatientDTO patientDTO) throws UnknownHostException {
return patientService.addPatient(patientDTO);
}
3.PUT
axios.put('/api/patient/UpdateHzupdate', app.StuInfo)
.then(function (response) {
getStuInfo(1, 10);
app.showUpdate = false;
app.$notify.info({type: '温馨提示', message: response.data.msg});
})
@PutMapping("UpdateHzupdate")
@ApiOperation("更新患者信息")
@OpetionLog("更新患者信息")
public Result updatePatient(@RequestBody PatientDTO patientDTO) throws UnknownHostException {
return patientService.updatePatient(patientDTO);
}
4.DELETE
axios.delete('/api/patient/delete/' + id)
.then(function (response) {
app.$notify.info({type: '温馨提示', message: response.data.msg});
getStuInfo(1, 10);
})
.catch(function (error) {
console.log(error);
});
@DeleteMapping("delete/{id}")
@ApiOperation("删除患者")
@OpetionLog("删除患者")
public Result deletePatient(@PathVariable Integer id) throws UnknownHostException {
return patientService.deletePatient(id);
}