RESTful 接口接收请求
@PostMapping
public Result add(@RequestBody CuUsers cuUsers) {
cuUsersService.save(cuUsers);
return ResultGenerator.genSuccessResult();
}
@DeleteMapping("/{id}")
public Result delete(@PathVariable Integer id) {
cuUsersService.deleteById(id);
return ResultGenerator.genSuccessResult();
}
@PutMapping
public Result update(@RequestBody CuUsers cuUsers) {
cuUsersService.update(cuUsers);
return ResultGenerator.genSuccessResult();
}
@GetMapping("/{id}")
public Result detail(@PathVariable Integer id) {
CuUsers cuUsers = cuUsersService.findById(id);
return ResultGenerator.genSuccessResult(cuUsers);
}
在AJAX中,type请求类型(get,post,delete,put)
在使用delete请求时,用data传参,而不是在url中传递
JNHC.json({
url: "http://localhost:8081/cu/wotype/",
type:"post",
data:{
_method:"delete",
id:id
},
callback: function (data) {
alert("删除成功!");
showTable();
}
})
data中添加_method参数,type类型为post;
在springboot 微服务中 需要在 @DeleteMapping(“/{id}”) 上放加@CrossOrigin注解;