Java响应结果类
package demo;
import java. io. Serializable;
import java. util. HashMap;
public class Response extends HashMap < String, Object> implements Serializable {
private static final long serialVersionUID = 1 L;
public Response ( ) {
super ( 8 ) ;
this . put ( "code" , "200" ) ;
this . put ( "msg" , "" ) ;
this . put ( "data" , ( Object) null) ;
this . put ( "success" , Boolean. valueOf ( true ) ) ;
}
public Response setCode ( Object code) {
this . put ( "code" , code) ;
return this ;
}
public Response setData ( Object data) {
this . put ( "data" , data) ;
return this ;
}
public Response setMessage ( String message) {
this . put ( "msg" , message) ;
return this ;
}
public String getCode ( ) {
return ( String) this . get ( "code" ) ;
}
public Object getData ( ) {
return this . get ( "data" ) ;
}
public String getMessage ( ) {
return ( String) this . get ( "msg" ) ;
}
public Response error ( ) {
return this . error ( "操作失败" ) ;
}
public Response success ( ) {
this . put ( "msg" , "操作成功" ) ;
return this ;
}
public Response error ( String message) {
this . put ( "code" , "0" ) ;
this . put ( "msg" , message) ;
this . put ( "success" , Boolean. valueOf ( false ) ) ;
return this ;
}
public Response putMessage ( String message) {
StringBuffer sbMsg = new StringBuffer ( ) ;
sbMsg. append ( this . get ( "msg" ) ) ;
sbMsg. append ( message) ;
sbMsg. append ( "<br>" ) ;
this . put ( "msg" , sbMsg. toString ( ) ) ;
return this ;
}
}