• 拦截器的使用,配置手机浏览器访问的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
  • 相关阅读:
    OCP-1Z0-053-V12.02-15题
    Boost.Asio性能测试
    使用asio搭建服务器
    boost::asio::ip::tcp::socket is connected?(如何知道socket的链接是链接或断开?)
    boost::async_read_some连续接收数据
    基于boost asio实现的支持ssl的通用socket框架
    Boost.Asio的使用技巧
    Matlab基本函数-expm函数
    Matlab基本函数-exp函数
    OCP-1Z0-053-V12.02-337题
  • 原文地址:https://www.cnblogs.com/hoge66/p/8459826.html
Copyright © 2020-2023  润新知