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

com.paas.aspect.BasicRequest Maven / Gradle / Ivy

package com.paas.aspect;

import java.util.Map;

/**
 * @ClassName BasicRequest
 * @Date 2020/12/8 14:56
 * @Auther wangyongyong
 * @Version 1.0
 * @Description 请求参数
 */
public class BasicRequest
{
    /**
     * 请求头部参数
     */
    private final transient static ThreadLocal> headers = new ThreadLocal<>();

    /**
     * 请求参数
     */
    private final transient static ThreadLocal> body = new ThreadLocal<>();

    private final transient static ThreadLocal> bodyName = new ThreadLocal<>();

    /**
     * 获取头部参数
     * @param key 头部 key
     * @return 头部值
     */
    public String getHeader(String key)
    {
        return (null == BasicRequest.headers.get()) ? null : BasicRequest.headers.get().get(key);
    }

    /**
     * 获取请求扩展 body 值
     * @param code body code
     * @return body 值
     */
    public Object getExtValue(String code)
    {
        return (null == BasicRequest.body.get()) ? null : BasicRequest.body.get().get(code);
    }

    /**
     * 获取请求扩展 body 名称
     * @param code body code
     * @return body 名称
     */
    public String getExtName(String code)
    {
        return (null == BasicRequest.bodyName.get()) ? null : BasicRequest.bodyName.get().get(code);
    }

    static void setHeaders(Map headers)
    {
        BasicRequest.headers.set(headers);
    }

    static void resetHeaders()
    {
        BasicRequest.headers.remove();
    }

    static void setBody(Map body)
    {
        BasicRequest.body.set(body);
    }

    static void setBodyName(Map bodyName)
    {
        BasicRequest.bodyName.set(bodyName);
    }

    static void clearBody()
    {
        BasicRequest.body.remove();
        BasicRequest.bodyName.remove();
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy