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

io.github.ye17186.myhelper.web.interceptor.MhInterceptor Maven / Gradle / Ivy

There is a newer version: 0.0.6
Show newest version
package io.github.ye17186.myhelper.web.interceptor;

import com.google.common.base.Charsets;
import io.github.ye17186.myhelper.core.utils.JsonUtils;
import io.github.ye17186.myhelper.core.web.response.ApiResp;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author ye17186
 * @since 2023-03-09
 */
@Slf4j
public abstract class MhInterceptor implements HandlerInterceptor {

    protected  void writeResp(HttpServletRequest request, HttpServletResponse response, ApiResp resp) throws IOException {

        String origin = request.getHeader("Origin");
        response.setHeader("Access-Control-Allow-Origin", origin);
        response.setCharacterEncoding(Charsets.UTF_8.name());
        response.setContentType("application/json; charset=utf-8");
        response.getWriter().write(JsonUtils.obj2Json(resp));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy