package com.fxf.separation.interceptor;

import com.fxf.separation.bean.DBContextHolder;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author FXF
 * @date 2019-10-14
 */
@Component
public class AccessInterceptor implements HandlerInterceptor {
	
	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object obj) {
		System.out.println(request.getMethod());
		if (request.getMethod().equals("GET")){
			DBContextHolder.slave();
		}else {
			DBContextHolder.master();
		}
		return true;
	}
}
