com.gitee.cn9750wang.webtools.vo.result.Result Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of web-tools Show documentation
Show all versions of web-tools Show documentation
web tools for spring-boot web project
The newest version!
/*
* Copyright 2021 wwy
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.gitee.cn9750wang.webtools.vo.result;
import com.gitee.cn9750wang.webtools.vo.page.EmptyPage;
import com.gitee.cn9750wang.webtools.vo.page.Page;
import com.gitee.cn9750wang.webtools.vo.result.data.CommonResult;
import com.gitee.cn9750wang.webtools.vo.result.error.ErrorMessage;
import com.gitee.cn9750wang.webtools.vo.result.page.PageResult;
import java.io.Serializable;
import java.util.Collection;
/**
* 返回内容的封装类
* @author anonym
* @param data属性的类型
*/
public interface Result extends Serializable {
/**
* http响应应该返回什么状态码
* @return StatusCode http状态码
*/
int getStatusCode();
/**
* 响应数据
* @return D 响应数据
*/
D getData();
/**
* 错误列表
* @return 错误信息列表
*/
Collection getErrors();
/**
* 将分页结果包装后返回
* @param page 分页对象
* @param 数据类型
* @return 包装后结果
*/
static PageResult to(Page page){
if(page == null || page.equals(EmptyPage.emptyPage())){
return Results.emptyPageResult();
}
return new PageResult<>(page);
}
/**
* 将查询结果包装后返回
* @param data 数据
* @param 数据类型
* @return 包装后结果
*/
static Result to(D data){
if(data == null){
return Results.emptyDataResult();
}
return new CommonResult<>(data);
}
}