All Downloads are FREE. Search and download functionalities are using the official Maven repository.

template.result_model.vm Maven / Gradle / Ivy

Go to download

自动生成增删改查代码插件,通过Maven插件配置,一键生成单表的所有CRUD操作

There is a newer version: 3.0.4
Show newest version
package ${package.ResultModel};

import ${package.ResultCodeEnum}.ResultCodeEnum;

import java.io.Serializable;

/**
 * 前后端交互对象
 *
 * @author ${author}
 * @since ${date}
 */
public class ResultModel implements Serializable {
	private static final long serialVersionUID = 8951721595994792067L;
	private Integer code;
	private String message;
	private T data;

	public ResultModel(Integer code, String message) {
		this.code = code;
		this.message = message;
	}

	public ResultModel(Integer code, String message, T data) {
		this.code = code;
		this.message = message;
		this.data = data;
	}

	public ResultModel(ResultCodeEnum resultCode) {
		this.code = resultCode.getCode();
		this.message = resultCode.getMessage();
	}

	public static  ResultModel resultModel(Integer code, String message) {
		return new ResultModel(code, message);
	}

	public static  ResultModel resultModel(ResultCodeEnum resultCode) {
		return new ResultModel(resultCode);
	}

	public static  ResultModel resultModel(Integer code, String message, T t) {
		return new ResultModel(code, message, t);
	}

	/**
     * 处理成功
     *
     * @param t
     * @param 
     * @return
     */
	public static  ResultModel success(T t) {
		ResultModel resultModel = new ResultModel<>(ResultCodeEnum.SUCCESS);
		resultModel.setData(t);
		return resultModel;
	}
	public static  ResultModel successNoData(String message) {
		return new ResultModel(ResultCodeEnum.SUCCESS.getCode(),message);
	}
	public static  ResultModel success() {
		return success("success");
	}

	/**
     * 业务处理失败
     *
     * @param t
     * @param 
     * @return
     */
	public static  ResultModel fail(T t) {
		ResultModel resultModel = new ResultModel<>(ResultCodeEnum.FAIL);
		resultModel.setData(t);
		return resultModel;
	}
	public static  ResultModel failNoData(String message) {
		return new ResultModel(ResultCodeEnum.FAIL.getCode(),message);
	}

	public static  ResultModel fail(String message, T date) {
		return new ResultModel(ResultCodeEnum.FAIL.getCode(), message, date);
	}
	public static  ResultModel fail() {
		return fail(null);
	}

	/**
     * 服务器内部错误
     *
     * @param t
     * @param 
     * @return
     */
	public static  ResultModel error(T t) {
		ResultModel resultModel = new ResultModel<>(ResultCodeEnum.INTERNAL_SERVER_ERROR);
		resultModel.setData(t);
		return resultModel;
	}
	public static  ResultModel errorNoData(String message) {
		return new ResultModel(ResultCodeEnum.INTERNAL_SERVER_ERROR.getCode(),message);
	}
	public static  ResultModel error() {
		return error(null);
	}


	/**
     * 参数错误
     *
     * @param t
     * @param 
     * @return
     */
	public static  ResultModel parameterError(T t) {
		ResultModel resultModel = new ResultModel<>(ResultCodeEnum.PARAMETER_ERROR);
		resultModel.setData(t);
		return resultModel;
	}
	public static  ResultModel parameterErrorNoData(String message) {
		return new ResultModel(ResultCodeEnum.PARAMETER_ERROR.getCode(),message);
	}
	public static  ResultModel parameterError() {
		return parameterError(null);
	}

	/**
     * 认证不通过
     *
     * @param t
     * @param 
     * @return
     */
	public static  ResultModel unAuthorized(T t) {
		ResultModel resultModel = new ResultModel<>(ResultCodeEnum.UNAUTHORIZED);
		resultModel.setData(t);
		return resultModel;
	}

	public static  ResultModel unAuthorized() {
		return unAuthorized(null);
	}

	public Integer getCode() {
		return code;
	}

	public void setCode(Integer code) {
		this.code = code;
	}

	public String getMessage() {
		return message;
	}

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

	public T getData() {
		return data;
	}

	public void setData(T data) {
		this.data = data;
	}
}