Guoguo-notes
主页
常用笔记
vue笔记及周边生态
  • 团队协作及规范
  • 项目框架及架构
  • 飞码篇
  • Java
  • React笔记
GitHub
主页
常用笔记
vue笔记及周边生态
  • 团队协作及规范
  • 项目框架及架构
  • 飞码篇
  • Java
  • React笔记
GitHub
  • Java

    • 1. AjaxResult.md
    • 2. Java 基础.md
    • 3. Java 注解.md
    • 4. MyBatis Plus.md
    • 5. MySQL完整.md
    • 6. Mybatis 语法.md
    • 7. StringBoot.md
    • 8. idea 插件.md
    • 9. idea快捷键.md
    • 10. java 代码片段.md
    • 11. mySql.md
    • 12. 分页插件使用.md
    • 13. 项目初始化.md

后端返前端

分页调用

     // 构建分页信息
        PageHelper.startPage(pageNum, pageSize);
        List<Employee> employees = employeeMapper.getUsers();
        PageInfo<Employee> employeePageInfo = new PageInfo<>(employees);

        return AjaxResult.pageSuccess(employeePageInfo.getList(), employeePageInfo.getTotal());

整体代码

package com.example.helpanimals.common;

import com.example.helpanimals.entity.Employee;
import org.springframework.util.StringUtils;

import java.util.HashMap;
import java.util.List;
//public class AjaxResult {
//}
//


public class AjaxResult extends HashMap<String, Object> {
    private static final long serialVersionUID = 1L;
    public static final String CODE_TAG = "code";
    public static final String MSG_TAG = "msg";
    public static final String DATA_TAG = "data";

    public AjaxResult() {
    }

    public AjaxResult(int code, String msg) {
        super.put("code", code);
        super.put("msg", msg);
    }

    public AjaxResult(int code, String msg, Object data) {
        super.put("code", code);
        super.put("msg", msg);
        if (!StringUtils.isEmpty(data)) {
            super.put("data", data);
        }
    }

    public <T> AjaxResult(int code, String msg, List<T> data, long total) {
        super.put("code", code);
        super.put("msg", msg);
        if (!StringUtils.isEmpty(data)) {
            super.put("data", data);
        }
        if (!StringUtils.isEmpty(total)) {
            super.put("total", total);
        }
    }

    public static AjaxResult success() {
        return success("操作成功");
    }

    public static AjaxResult success(Object data) {
        return success("操作成功", data);
    }

    public static AjaxResult success(String msg) {
        return success(msg, (Object) null);
    }

    public static <T> AjaxResult pageSuccess(List<T> data, long total) {
        return new AjaxResult(200, "操作成功", data, total);
    }

    public static AjaxResult success(String msg, Object data) {
        return new AjaxResult(200, msg, data);
    }

    public static AjaxResult error() {
        return error("操作失败");
    }

    public static AjaxResult error(String msg) {
        return error(msg, (Object) null);
    }

    public static AjaxResult error(String msg, Object data) {
        return new AjaxResult(500, msg, data);
    }

    public static AjaxResult error(int code, String msg) {
        return new AjaxResult(code, msg, (Object) null);
    }
}



Edit this page
Last Updated:
Contributors: 袁果锅
Next
2. Java 基础.md