AjaxResult

md笔记

// 成功与否返回对象
@Data
public class AjaxResult {
    private Boolean success = true;
    private String message = "操作成功!";

    public AjaxResult() {
    }

    //对象由自己创建,不交给外部创建
    public static AjaxResult me(){
        return new AjaxResult();
    }

    //只需要一个返回失败  链式编程
    public AjaxResult setMessage(String message) {
        this.success = false;
        this.message = message;
        return this;
    }
}

pethome

package cn.itsource.basic.util;
import lombok.Data;
/**
 * 成功与否返回对象
 */
@Data
public class AjaxResult {
    private Boolean success = true;
    private String message = "操作成功!";
    private Object resultObj = null;//存储需要返回给前端的扩展值

    public AjaxResult() {
    }

    /**
     * 提供一个返回错误的构造函数
     * @param message
     */
   /* public AjaxResult (String message) {
        this.success = false;
        this.message = message;
    }*/

    /**
     * 对象由自己创建,不交给外部创建
     * @return
     */
    public static AjaxResult me(){
        return new AjaxResult();
    }

    /**
     * 只需要一个返回失败  链式编程
     * @param message
     * @return
     */
    public AjaxResult setMessage(String message) {
        this.success = false;
        this.message = message;
        return this;
    }

    public AjaxResult setResultObj(Object resultObj) {
        this.resultObj = resultObj;
        return this;
    }

    public AjaxResult setSuccess(Boolean success) {
        this.success = success;
        return this;
    }
}

hrm

package itsource.cw.util;

//Ajax请求响应对象的类
public class AjaxResult {

    private boolean success = true;
    private String message = "操作成功!";
    //返回到前台对象
    private Object resultObj;

    
    public boolean isSuccess() {
        return success;
    }

    public AjaxResult setSuccess(boolean success) {
        this.success = success;
        return this;
    }

    public String getMessage() {
        return message;
    }

    public AjaxResult setMessage(String message) {
        this.message = message;
        return this;
    }

    public Object getResultObj() {
        return resultObj;
    }

    public AjaxResult setResultObj(Object resultObj) {
        this.resultObj = resultObj;
        return this;
    }

    //AjaxResult.me()成功
    //AjaxResult.me().setMessage()成功
    //AjaxResult.me().setSuccess(false),setMessage("失败");
    public  static AjaxResult me(){
        return new AjaxResult();
    }



    /*
    //成功
    public AjaxResult() {
    }

    //失败并且有提示
    public AjaxResult(String message) {
        this.success = false;
        this.message = message;
    }*/
}

cms

package cn.itsource.util;

public class AjaxResult {

	private Boolean result = true;
	private String error;

	public AjaxResult(Boolean result, String error) {
		super();
		this.result = result;
		this.error = error;
	}

	public AjaxResult() {
		super();
		// TODO Auto-generated constructor stub
	}

	public Boolean getResult() {
		return result;
	}

	public void setResult(Boolean result) {
		this.result = result;
	}

	public String getError() {
		return error;
	}

	public void setError(String error) {
		this.error = error;
	}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值