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


    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>
    

      

    www.beicaiduo.com
  • 相关阅读:
    Python max() 函数
    Python log10() 函数
    Python log() 函数
    Python fabs() 函数
    Java开源-astar:A 星算法
    9款超绚丽的HTML5/CSS3应用和动画特效
    Java中处理异常的9个最佳实践
    Java泛型
    Android界面性能调优手册
    正确使用Android性能分析工具——TraceView
  • 原文地址:https://www.cnblogs.com/hoge66/p/8459826.html
Copyright © 2020-2023  润新知