Response规范

BaseResponse等这些统一的返回给前端的类,不要随意增加字段

code为返回的状态;

msg为状态描述;

其余数据都放入T data中;

public BaseResponse Searching( ) throws Exception {

BaseResponse baseResponse =new BaseResponse();

    long s =0;

    mongoService.Search();

//这就是自己添加的字段,并不规范

    baseResponse.setNum(mongoService.Search() -firstnum);

//正确的做法如下

    Map result = Maps.newHashMap();

    result.put("sendNum", sendService.getI());

    baseResponse.setData(result);

    System.out.println(mongoService.Search() -firstnum);

    return baseResponse;

}

你可能感兴趣的:(Response规范)