1,非Json格式入参
@PostMapping(value = "/init", produces = MediaType.APPLICATION_JSON_VALUE)
public ResultDTO initDoctorConfig(@Valid User param) {
do something...
}
@PostMapping(value = "/init", produces = MediaType.APPLICATION_JSON_VALUE)
public ResultDTO initDoctorConfig(int id) {
do something...
}
@PostMapping(value = "/init", produces = MediaType.APPLICATION_JSON_VALUE)
public ResultDTO initDoctorConfig(@RequestParam int id) {
do something...
}
@PostMapping(value = "/init", produces = MediaType.APPLICATION_JSON_VALUE)
public ResultDTO initDoctorConfig(@RequestBody int id) {
do something...
2.JSON入参
2.1 单个或多个独立参数
@PostMapping(value = "/order/detail", produces = MediaType.APPLICATION_JSON_VALUE)
public ResultDTO getInfo(@RequestBody JSONObject jsonParams) {
long id = jsonParams.getLong("id");
String name = jsonParams.getString("name");
}
2.2 封装参数
@PostMapping(value = "/init", produces = MediaType.APPLICATION_JSON_VALUE)
public ResultDTO initConfig(@Valid @RequestBody RequestParam param) {
return initService.initConfig(param);
}
其中封装入参对象就是一个包含各入参函数对象的Object
这里同步做了数据校验,可忽略也可在其项目参考,其中包资源
import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
@Data
public class RequestParam {
private long id;
@NotBlank(message = "姓名不能为空")
private String name;
@NotBlank(message = "年龄不能为空")
private String age;
}