springboot + shiro+登陸 微信登陸 次數驗證資料

分享一個朋友的人工智能教程。零基礎!通俗易懂!風趣幽默!你們能夠看看是否對本身有幫助,點擊查看教程。html

 

1.https://blog.csdn.net/xtiawxf/article/details/52571949java

https://blog.csdn.net/hxm_code/article/details/50136173ajax

https://blog.csdn.net/melodykke/article/details/81362447spring

https://www.cnblogs.com/foxting/p/6790331.html?utm_source=itdadao&utm_medium=referral 登陸次數sql

 

 

 

springboot2+shiro 無權限、異常、異步返回json

http://www.bubuko.com/infodetail-1629577.htmltomcat

/**
 * 對controller異常進行全局處理
 * 區分了對普通請求和ajax請求的異常處理,普通請求返回到配置的errorCode頁面,或者返回到指定的頁面
 * @author
 * 
 */
public class CustomException extends SimpleMappingExceptionResolver {
    private final transient Logger logger = LoggerFactory.getLogger(getClass());

    @Override
    protected ModelAndView doResolveException(HttpServletRequest request,
            HttpServletResponse response, Object handler, Exception ex) {
        String viewName = determineViewName(ex, request);
        if (viewName != null) {// JSP格式返回
            //增長普通提交返回到本身頁面errorPage
            String errorPage = String.valueOf(request.getAttribute("errorPage"));
            //回到本身的頁面
            if(StringUtils.isNotBlank(errorPage)){
                viewName = errorPage;
            }
            if (!(request.getHeader("accept").indexOf("application/json") > -1 || (request
                    .getHeader("X-Requested-With") != null && request
                    .getHeader("X-Requested-With").indexOf("XMLHttpRequest") > -1))) {
                // 若是不是異步請求
                // Apply HTTP status code for error views, if specified.
                // Only apply it if we‘re processing a top-level request.
                Integer statusCode = determineStatusCode(request, viewName);
                if (statusCode != null) {
                    applyStatusCodeIfPossible(request, response, statusCode);
                }
                return getModelAndView(viewName, ex, request);
            } else {// JSON格式返回
                try {
                    Map<String, Object> jsonMap = new HashMap<String, Object>();
                    // 返回是錯誤
                    jsonMap.put(BaseController.AJAX_RESULT, false);
                    jsonMap.put(BaseController.RESULT_MESSAGE, ex.getMessage());
                    response.setContentType("text/html;charset=UTF-8");
                    PrintWriter writer = response.getWriter();
                    writer.write(JSON.toJSONString(jsonMap));
                    writer.close();
                } catch (Exception e) {
                    logger.error("doResolveException", "系統異常!", e);
                }
                return null;

            }
        } else {
            return null;
        }
    }
}


<bean class="cn.tomcat.quickstart.exception.CustomException">  
        <!-- 定義默認的異常處理頁面,當該異常類型的註冊時使用 -->  
        <property name="defaultErrorView" value="error"></property>  
        <!-- 定義異常處理頁面用來獲取異常信息的變量名,默認名爲exception -->  
        <property name="exceptionAttribute" value="ex"></property>  
        <!-- 定義須要特殊處理的異常,用類名或徹底路徑名做爲key,異常也頁名做爲值 -->  
        <property name="exceptionMappings">  
            <props>  
                <prop key="IOException">error/ioexp</prop>  
                <prop key="java.sql.SQLException">error/sqlexp</prop>  
            </props>  
        </property>  
    </bean>  
相關文章
相關標籤/搜索