接口返回消息工具类
public class AjaxResult extends HashMap < String, Object> {
public static final String CODE_TAG= "code" ;
public static final String MSG_TAG= "msg" ;
public static final String DATA_TAG= "data" ;
public AjaxResult ( ) {
}
public enum Type{
SUCCESS ( 0 ) ,
WARN ( 301 ) ,
ERROR ( 500 ) ;
private final int value;
Type ( int value) {
this . value = value;
}
public int value ( ) {
return this . value;
}
}
public AjaxResult ( Type type, String msg) {
super . put ( CODE_TAG, type. value) ;
super . put ( MSG_TAG, msg) ;
}
public AjaxResult ( Type type, String msg, Object data) {
super . put ( CODE_TAG, type. value) ;
super . put ( MSG_TAG, msg) ;
if ( data!= null) {
super . put ( DATA_TAG, data) ;
}
}
public static AjaxResult success ( String msg, Object data) {
return new AjaxResult ( Type. SUCCESS, msg, data) ;
}
public static AjaxResult success ( String msg) {
return success ( msg, null) ;
}
public static AjaxResult success ( Object data) {
return success ( "操作成功" , data) ;
}
public static AjaxResult success ( ) {
return success ( "操作成功" , null) ;
}
public static AjaxResult warn ( String msg, Object data) {
return new AjaxResult ( Type. WARN, msg, data) ;
}
public static AjaxResult warn ( String msg) {
return warn ( msg, null) ;
}
public static AjaxResult error ( ) {
return AjaxResult. error ( "操作失败" ) ;
}
public static AjaxResult error ( String msg) {
return error ( msg, null) ;
}
public static AjaxResult error ( String msg, Object data) {
return new AjaxResult ( Type. ERROR, msg, data) ;
}
}