接收json格式的数据
前端输入部分参数能够正常调用,我在使用APIFOX时必须输入全部参数,输入部分参数会报400错误
@PostMapping("/addStudent")
public Result addStudent(@RequestBody Student student){
int i = studentService.addStudent(student);
return new Result(200,"成功",i);
}
@PathVariable
接收参数格式为http://localhost:8080/student/deleteStudent1001
参数前不必加问号
@DeleteMapping("/deleteStudent{id}")
public Result deleteStudent(@PathVariable("id") Integer id){
boolean b = studentService.removeById(id);
return new Result(200,"成功",b);
}
直接写在请求中的参数
类似于接收参数格式为http://localhost:8080/student/deleteStudent?id=1001
将参数封装在一个实体类中通过表单来传递参数
name需要与实体类的属性一一对应
后端为
@PostMapping("/addGoods")
public String add(Good good){
goodService.addGoods(good);
return "redirect:/Goods/getAllGoods";
}
HttpServletRequest获取数据
处理的请求为http://localhost:8080/student/deleteStudent?id=1001
得到请求中的参数
@GetMapping("/get")
public String get(HttpServletRequest request){
return request.getQueryString();
}
@RequestParam获取参数
与直接写在请求中的参数类似,可以起到重命名的作用
@RequestParam(“sid”)中的sid为前端的参数名
也可以一个一个地获取前端表单中的所有数据
@GetMapping("/get")
public void get(@RequestParam("sid")Integer id){
system.out.println(id);
}



