国产亚洲精品福利在线无卡一,国产精久久一区二区三区,亚洲精品无码国模,精品久久久久久无码专区不卡

當前位置: 首頁 > news >正文

營銷網站建設是什么網站設計的流程

營銷網站建設是什么,網站設計的流程,自適應網站會影響推廣,做哪些網站比較好一、統(tǒng)一用戶登錄權限驗證 1.1Spring攔截器 實現(xiàn)攔截器需要以下兩步: 1.創(chuàng)建自定義攔截器,實現(xiàn) HandlerInterceptor 接?的 preHandle(執(zhí)行具體方法之前的預處理)方法。 2.將?定義攔截器加? WebMvcConfigurer 的 addIntercept…

一、統(tǒng)一用戶登錄權限驗證

1.1Spring攔截器

實現(xiàn)攔截器需要以下兩步:
1.創(chuàng)建自定義攔截器,實現(xiàn) HandlerInterceptor 接?的 preHandle(執(zhí)行具體方法之前的預處理)方法。
2.將?定義攔截器加? WebMvcConfigurer 的 addInterceptors 方法中

1.1.1自定義攔截器

在這里插入圖片描述

package com.example.demo.interceptor;import org.springframework.web.servlet.HandlerInterceptor;import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;/*** 創(chuàng)建一個登錄的攔截器*/
public class LoginInterceptor implements HandlerInterceptor {//返回true表示驗證通過,可以執(zhí)行后面的方法;// 但是返回false表示驗證失敗,后面的代碼就不能執(zhí)行了@Overridepublic boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {HttpSession session = request.getSession(false);if (session != null && session.getAttribute("userinfo") != null){//表明用戶已登錄return true;}//執(zhí)行到此行,表明驗證未通過,自動跳轉到登錄頁面response.sendRedirect("login.html");return false;}
}

1.1.2將攔截器配置給當前項目

在這里插入圖片描述

package com.example.demo.config;import com.example.demo.interceptor.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;@Configuration
public class AppConfig implements WebMvcConfigurer {@Autowiredprivate LoginInterceptor loginInterceptor;/*** 給當前項目添加攔截器* @param registry*/@Overridepublic void addInterceptors(InterceptorRegistry registry) {registry.addInterceptor(loginInterceptor).addPathPatterns("/**")//攔截使用的url.excludePathPatterns("/user/reg")//不攔截/user/reg.excludePathPatterns("/**/*.html");//攔截/**/*.html}
}

在這里插入圖片描述

1.2攔截器實現(xiàn)原理

在這里插入圖片描述

二、統(tǒng)?異常處理

使用 @ControllerAdvice + @ExceptionHandler來實現(xiàn)
@ControllerAdvice:控制器通知類
@ExceptionHandler:異常處理器
結合表示當出現(xiàn)異常的時候執(zhí)行某個通知。

2.1創(chuàng)建異常類

添加@ControllerAdvice 注解
在這里插入圖片描述

2.2實現(xiàn)異常的封裝方法

添加@ExceptionHandler注解
在這里插入圖片描述

package com.example.demo.config;import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;import java.util.HashMap;@ControllerAdvice//對控制器進行功能增強(當前類為統(tǒng)一封裝類)
public class MyExceptionResult {@ResponseBody@ExceptionHandler(Exception.class)public HashMap<String,Object> myException(Exception e){HashMap<String,Object> result = new HashMap<String,Object>();result.put("state",-1);result.put("msg","默認異常"+e.getMessage());result.put("data",null);return result;}
}

三、統(tǒng)?數據格式返回

以使? @ControllerAdvice + ResponseBodyAdvice實現(xiàn)
在這里插入圖片描述

package com.example.demo.config;import org.springframework.core.MethodParameter;
import org.springframework.http.MediaType;
import org.springframework.http.server.ServerHttpRequest;
import org.springframework.http.server.ServerHttpResponse;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice;import java.util.HashMap;@ControllerAdvice
public class MyResponseBodyAdvice implements ResponseBodyAdvice {//是否要重寫的方法改為true,true表示在返回數據之前,進行統(tǒng)一的格式封裝@Overridepublic boolean supports(MethodParameter returnType, Class converterType) {return true;}@Overridepublic Object beforeBodyWrite(Object body, MethodParameter returnType, MediaType selectedContentType, Class selectedConverterType, ServerHttpRequest request, ServerHttpResponse response) {HashMap<String,Object> result = new HashMap<>();result.put("state",1);result.put("data",body);result.put("msg","");return result;}
}
http://aloenet.com.cn/news/31162.html

相關文章:

  • 新博念 足球網站開發(fā)天津疫情最新情況
  • 成都網站建設定制開發(fā)系統(tǒng)淘寶關鍵詞搜索量查詢工具
  • 玉溪哪有網站建設服務公司想要推廣頁
  • 網頁設計英文青島關鍵詞優(yōu)化平臺
  • 拓普網站建設seo點擊優(yōu)化
  • 如果你會建網站外貿新手怎樣用谷歌找客戶
  • 網站推廣適合哪種公司做明星百度指數排名
  • 網站標題堆砌關鍵詞國際足聯(lián)世界排名
  • 免費建立個人網站促銷策略的四種方式
  • 企業(yè)管理咨詢公司招聘成都自動seo
  • 廈門網站建設多少錢軟文編輯器
  • 廈門服裝企業(yè)網站推廣最新小組排名
  • 做網站重要標簽成都seo優(yōu)化排名推廣
  • .net網站開發(fā)文檔教育培訓網站模板
  • 國家高新技術企業(yè)證書圖片北京seo分析
  • 程序員做博彩類的網站犯法嗎青島網站建設運營推廣
  • 河北高端網站定制公司seo營銷優(yōu)化軟件
  • 戴爾網站建設成功的關鍵網站怎么做收錄
  • wordpress數據庫導出網址鏈接關鍵詞推廣優(yōu)化外包
  • 浙江溫州最新消息鄭州seo外包公司哪家好
  • 怎樣開發(fā)公司的網站建設寧波seo怎么推廣
  • 清潔公司百度關鍵詞在線優(yōu)化
  • 動態(tài)網站開發(fā)工程師—aspseo一鍵優(yōu)化
  • 網站建設的需求怎么寫項目優(yōu)化seo
  • 寧波網站建設c nb網站優(yōu)化網
  • 全面做好政府網站建設管理工作的通知免費營銷培訓
  • 標識設計廠家珠海百度搜索排名優(yōu)化
  • 網站制作詳細流程凈水器十大品牌
  • 網站做視頻在線觀看網址網站開發(fā)合同
  • 陽江招聘網站哪個靠譜松原頭條新聞今日新聞最新