中文亚洲精品无码_熟女乱子伦免费_人人超碰人人爱国产_亚洲熟妇女综合网

當(dāng)前位置: 首頁(yè) > news >正文

營(yíng)銷(xiāo)網(wǎng)站建設(shè)是什么網(wǎng)站設(shè)計(jì)的流程

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

一、統(tǒng)一用戶登錄權(quán)限驗(yàn)證

1.1Spring攔截器

實(shí)現(xiàn)攔截器需要以下兩步:
1.創(chuàng)建自定義攔截器,實(shí)現(xiàn) HandlerInterceptor 接?的 preHandle(執(zhí)行具體方法之前的預(yù)處理)方法。
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)建一個(gè)登錄的攔截器*/
public class LoginInterceptor implements HandlerInterceptor {//返回true表示驗(yàn)證通過(guò),可以執(zhí)行后面的方法;// 但是返回false表示驗(yàn)證失敗,后面的代碼就不能執(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í)行到此行,表明驗(yàn)證未通過(guò),自動(dòng)跳轉(zhuǎn)到登錄頁(yè)面response.sendRedirect("login.html");return false;}
}

1.1.2將攔截器配置給當(dāng)前項(xiàng)目

在這里插入圖片描述

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;/*** 給當(dāng)前項(xiàng)目添加攔截器* @param registry*/@Overridepublic void addInterceptors(InterceptorRegistry registry) {registry.addInterceptor(loginInterceptor).addPathPatterns("/**")//攔截使用的url.excludePathPatterns("/user/reg")//不攔截/user/reg.excludePathPatterns("/**/*.html");//攔截/**/*.html}
}

在這里插入圖片描述

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

在這里插入圖片描述

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

使用 @ControllerAdvice + @ExceptionHandler來(lái)實(shí)現(xiàn)
@ControllerAdvice:控制器通知類(lèi)
@ExceptionHandler:異常處理器
結(jié)合表示當(dāng)出現(xiàn)異常的時(shí)候執(zhí)行某個(gè)通知。

2.1創(chuàng)建異常類(lèi)

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

2.2實(shí)現(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//對(duì)控制器進(jìn)行功能增強(qiáng)(當(dāng)前類(lèi)為統(tǒng)一封裝類(lèi))
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","默認(rèn)異常"+e.getMessage());result.put("data",null);return result;}
}

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

以使? @ControllerAdvice + ResponseBodyAdvice實(shí)現(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 {//是否要重寫(xiě)的方法改為true,true表示在返回?cái)?shù)據(jù)之前,進(jìn)行統(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://www.risenshineclean.com/news/31162.html

相關(guān)文章:

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