1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
| @Api(tags = {"学生管理"}) @RestController @RequestMapping("/student") public class StudentController {
@Autowired StudentService studentService;
@ApiOperation("查看学生列表") @GetMapping("/list") public R getStudentList() { List<Student> students = studentService.list(); if (students != null && students.size() != 0) { return R.ok().data("students", students); }else return R.error(); } }
@Data public class R {
@ApiModelProperty(value = "是否成功") private Boolean success;
@ApiModelProperty(value = "返回状态码") private Integer code;
@ApiModelProperty(value = "返回消息") private String message;
@ApiModelProperty(value = "返回数据") private Map<String, Object> data = new HashMap<>();
private R(){}
public static R ok(){ R r = new R(); r.setSuccess(true); r.setCode(ResultCode.SUCCESS); r.setMessage("成功"); return r; }
public static R error(){ R r = new R(); r.setSuccess(false); r.setCode(ResultCode.ERROR); r.setMessage("失败"); return r; }
public R success(Boolean success){ this.setSuccess(success); return this; }
public R code(Integer code){ this.setCode(code); return this; }
public R message(String message){ this.setMessage(message); return this; }
public R data(String key, Object value){ this.data.put(key, value); return this; }
public R data(Map<String, Object> map){ this.setData(map); return this; } }
|