一、代码
@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; try { // StudentExample studentExample = new StudentExample(); // StudentExample.Criteria criteria = studentExample.createCriteria(); // 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.println(sb.toString()); 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); }
二、页面
三、请求