欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

工具类

程序员文章站 2022-03-03 10:26:35
...

工具类:

  1. Result
package com.test.user.common;


public class Result {

    private final static String SUCCESS_CODE = "200";
    private final static String ERROR_CODE = "400";

    private String code;
    private Object data;
    private String msg;

    private Result() {
    }

    public static Result success() {
        return new Result().setCode(SUCCESS_CODE);
    }

    public static Result success(Object object) {
        return new Result().setCode(SUCCESS_CODE).setData(object);
    }

    public static Result error(String msg) {
        return new Result().setMsg(msg).setCode(ERROR_CODE);
    }

    public String getCode() {
        return code;
    }

    public Result setCode(String code) {
        this.code = code;
        return this;
    }

    public Object getData() {
        return data;
    }

    public Result setData(Object data) {
        this.data = data;
        return this;
    }

    public String getMsg() {
        return msg;
    }

    public Result setMsg(String msg) {
        this.msg = msg;
        return this;
    }

}

  1. BlankUtil
package com.test.util;

import java.util.List;
import java.util.Map;

public abstract class BlankUtil {

	private BlankUtil(){
	}

	public static boolean IsBlank(Object obj){

		if(obj == null)
			return true;

		if(obj instanceof List)
			if(((List)obj).size()==0)
				return true;

		if(obj instanceof Map)
			if(((Map)obj).size()==0)
				return true;

		if(obj instanceof String)
			if(((String)obj).trim().length()==0)
				return true;
		return false;
	}

	public static boolean IsNotBlank(Object obj){
		return !IsBlank(obj);
	}

}

相关标签: 工具类