问题描述:
方法代码为:
@PutMapping(path = "{studentId}")
public void updateStudent(
@PathVariable("studentId") Long studentId,
@PathVariable(required = false) String name,
@PathVariable(required = false) String email) {
System.out.println(studentId + " " + " " + name + " " + email);
studentService.updateStudent(studentId, name, email);
}
使用Put请求:
localhost:8080/api/v1/student/1?name=Maria
收到的参数为:
studentId=1, name = null, email = null.
解决方法
将updateStudent()中name与email参数的
@PathVariable()
修改为@RequestParam(required = fail)
即可。