json返回信息

This commit is contained in:
none 2023-02-07 17:27:39 +08:00
parent f4909257ae
commit ebd77f97d4
2 changed files with 53 additions and 2 deletions

View File

@ -7,6 +7,7 @@ import org.springframework.web.bind.annotation.RestController;
import xyz.playedu.api.domain.AdminUser;
import xyz.playedu.api.service.impl.AdminUserServiceImpl;
import xyz.playedu.api.types.PaginationResult;
import xyz.playedu.api.types.ResponseBody;
@RestController
public class AdminUserController {
@ -15,9 +16,9 @@ public class AdminUserController {
private AdminUserServiceImpl adminUserService;
@GetMapping("/admin/user/index")
public PaginationResult<AdminUser> List(@RequestParam("page") Integer page, @RequestParam("size") Integer size) {
public ResponseBody<Object> List(@RequestParam("page") Integer page, @RequestParam("size") Integer size) {
PaginationResult<AdminUser> result = adminUserService.paginate(page, size, null);
return result;
return ResponseBody.data(result);
}
}

View File

@ -0,0 +1,50 @@
package xyz.playedu.api.types;
public class ResponseBody<T> {
private Integer code;
private String msg;
private T data;
public Integer getCode() {
return code;
}
public void setCode(Integer code) {
this.code = code;
}
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
public T getData() {
return data;
}
public void setData(T data) {
this.data = data;
}
public ResponseBody(Integer code, String msg, T data) {
this.code = code;
this.msg = msg;
this.data = data;
}
public static ResponseBody<String> success(String msg) {
return new ResponseBody<>(0, msg, null);
}
public static ResponseBody<Object> data(Object data) {
return new ResponseBody<>(0, "", data);
}
public static ResponseBody<String> error(String msg, Integer code) {
return new ResponseBody<>(code, msg, null);
}
}