@ApiParam和@RequestHeader接收参数的区别
⼀、代码
@ApiOperation(value = "查询学⽣信息")
@GetMapping(value = "/select/student")
@ApiImplicitParams({
@ApiImplicitParam(name="userName",value="学⽣姓名",dataType="string", paramType = "query",example="Tom"),
@ApiImplicitParam(name="age",value="年龄",dataType="int", paramType = "query")})
public CommonResult selectStudent(
@ApiParam(name="userName",value = "学⽣姓名") String userName,
@ApiParam(name="age",value = "年龄") Integer age) {
List<Student> list;
param name
try {
//            StudentExample studentExample = new StudentExample();
//            StudentExample.Criteria criteria = ateCriteria();
//            criteria.andUserNameEqualTo(userName);
//            criteria.andAgeEqualTo(age);
//            list = studentService.selectByExample(studentExample);
list = studentService.selectAll();
} catch (Exception e) {
System.out.println(e);
return CommonUtil.buildResponse(ResultCode.SYSTEM_ERROR, ResultCode.SYSTEM_ERROR_MSG);
}
JSONObject result = new JSONObject();
result.put("students", list);
return CommonUtil.buildResponse(ResultCode.SUCCESS, ResultCode.SUCCESS_MSG,result);
}
@ApiOperation("查询学⽣信息")
@ApiResponses(@ApiResponse(code = ResultCode.PARAM_ERROR, message = ResultCode.PARAM_ERROR_MSG))
@ApiImplicitParams({@ApiImplicitParam(name = "userName", value = "学⽣姓名", required = true),
@ApiImplicitParam(name = "age", value = "年龄", required = false),
@ApiImplicitParam(name = "phone", value = "⼿机号码", required = false)}
)
@GetMapping(value = "/select/student2")
public CommonResult selectStudent2(@RequestHeader(value = "userName", required = true) String userName,
@RequestHeader(value = "age", required = false) String age,
@RequestHeader(value = "phone", required = false) String phone){
List<Student> list;
try {
StringBuilder sb = new StringBuilder();
sb.append("userName:" + userName);
sb.append("-");
sb.append("age:" + age);
sb.append("-");
sb.append("phone:" + phone);
System.out.String());
list = studentService.selectAll();
} catch (Exception e) {
System.out.println(e);
return CommonUtil.buildResponse(ResultCode.SYSTEM_ERROR, ResultCode.SYSTEM_ERROR_MSG);
}
JSONObject result = new JSONObject();
result.put("students", list);
return CommonUtil.buildResponse(ResultCode.SUCCESS, ResultCode.SUCCESS_MSG,result);
}
⼆、页⾯
三、请求

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。