package com.ruoyi.common.filter;

import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import com.github.pagehelper.PageHelper;

/**
 * 清理 PageHelper 线程变量，避免 Tomcat 线程复用导致分页参数泄漏到后续请求。
 */
public class PageHelperClearFilter implements Filter
{
    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
            throws IOException, ServletException
    {
        PageHelper.clearPage();
        try
        {
            chain.doFilter(request, response);
        }
        finally
        {
            PageHelper.clearPage();
        }
    }
}
