java检测是不是移动端访问

java

浏览数:346

2019-1-7


request可以用别的代替

    private static boolean isMobile(){

        HttpServletRequest request = ThreadContextHolder.getHttpRequest();
        if(request==null) return false;
        String user_agent = request.getHeader("user-agent");
        if(StringUtil.isEmpty(user_agent)) return false;

        String userAgent = user_agent.toLowerCase();

        if(userAgent.contains("android" ) || userAgent.contains("iphone"))
        {
            return true;
        }
        return false;   }