All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.kasinf.framework.rest.web.controller.BaseController Maven / Gradle / Ivy

There is a newer version: 1.4.0
Show newest version
package com.kasinf.framework.rest.web.controller;

import com.kasinf.framework.rest.eneity.AbstractEntity;
import com.kasinf.framework.core.response.BaseResponse;
import com.kasinf.framework.core.response.HttpCode;
import com.kasinf.framework.rest.web.service.BaseService;

import java.io.Serializable;

/**
 * @author lkhsh
 * 基础请求返回
 */
public interface BaseController {

    /**
     * 获取对应的service
     *
     * @return BaseService
     */
    BaseService getBaseService();

    /**
     * 获取实体类型
     *
     * @return Class
     */
    Class getEntityClass();

    /**
     * 返回自定义成功消息字符串,覆盖状态码中的默认描述
     *
     * @param msg      消息
     * @param httpCode 状态码
     * @return {@link BaseResponse}
     */
    default BaseResponse msg(HttpCode httpCode, String msg) {
        return BaseResponse.msg(httpCode, msg);
    }

    /**
     * 设置无正文的响应
     *
     * @return {@link BaseResponse}
     */
    default BaseResponse success() {
        return BaseResponse.success();
    }

    /**
     * 设置无正文的响应
     *
     * @param data 返回主体
     * @return {@link BaseResponse}
     */
    default BaseResponse success(Object data) {
        return BaseResponse.success(data);
    }

    /**
     * 设置错误状态码
     *
     * @param httpCode 状态码
     * @return {@link BaseResponse}
     */
    default BaseResponse error(HttpCode httpCode) {
        return BaseResponse.error(httpCode);
    }

    /**
     * 设置响应代码
     *
     * @param httpCode 响应代码
     * @param data     数据
     * @return {@link BaseResponse}
     */
    default BaseResponse setModelMap(HttpCode httpCode, Object data) {
        return BaseResponse.setModelMap(httpCode, data);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy