码迷,mamicode.com
首页 > 移动开发 > 详细

拦截器的使用,配置手机浏览器访问的h5页面

时间:2018-02-22 21:31:36      阅读:248      评论:0      收藏:0      [点我收藏+]

标签:log   定义   拦截器   exce   after   tree   pos   tab   ice   

package com.thinkgem.jeesite.modules.sys.interceptor;

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

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import com.thinkgem.jeesite.common.service.BaseService;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.common.utils.UserAgentUtils;

/**
 * 手机端视图拦截器
 * @author 
 * @version 2014-9-1
 */
public class MobileInterceptor extends BaseService implements HandlerInterceptor {
	
	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, 
			Object handler) throws Exception {
		return true;
	}

	@Override
	public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, 
			ModelAndView modelAndView) throws Exception {
		if (modelAndView != null){
			// 如果是手机或平板访问的话,则跳转到手机视图页面。
			if(UserAgentUtils.isMobileOrTablet(request) && !StringUtils.startsWithIgnoreCase(modelAndView.getViewName(), "redirect:")){
				modelAndView.setViewName("mobile/" + modelAndView.getViewName());
			}
		}
	}

	@Override
	public void afterCompletion(HttpServletRequest request, HttpServletResponse response, 
			Object handler, Exception ex) throws Exception {
		
	}

}

  配置文件spring-mvc.xml:

<!-- 拦截器配置,拦截顺序:先执行后定义的,排在第一位的最后执行。-->
	<mvc:interceptors>
		<mvc:interceptor>
			<mvc:mapping path="${adminPath}/**" />
			<mvc:exclude-mapping path="${adminPath}/"/>
			<mvc:exclude-mapping path="${adminPath}/login"/>
			<mvc:exclude-mapping path="${adminPath}/sys/menu/tree"/>
			<mvc:exclude-mapping path="${adminPath}/sys/menu/treeData"/>
			<mvc:exclude-mapping path="${adminPath}/oa/oaNotify/self/count"/>
			<bean class="com.thinkgem.jeesite.modules.sys.interceptor.LogInterceptor" />
		</mvc:interceptor>
		<!-- 手机视图拦截器 -->
		<mvc:interceptor>
			<mvc:mapping path="/**" />
			<bean class="com.thinkgem.jeesite.modules.sys.interceptor.MobileInterceptor" />
		</mvc:interceptor>
	</mvc:interceptors>

  

拦截器的使用,配置手机浏览器访问的h5页面

标签:log   定义   拦截器   exce   after   tree   pos   tab   ice   

原文地址:https://www.cnblogs.com/hoge66/p/8459826.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!