欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

springboot 如何重定向redirect 并隱藏參數(shù)

 更新時(shí)間:2021年09月02日 08:36:38   作者:wgxaszc8  
這篇文章主要介紹了springboot 如何重定向redirect 并隱藏參數(shù)的操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教

springboot 重定向redirect 并隱藏參數(shù)

在做全局異常處理的時(shí)候,碰到重定向到全局錯(cuò)誤頁(yè)面

所謂隱藏參數(shù)無(wú)非是把參數(shù)放到了session中,再重定向后將該值清除

1、全局異常處理方法

@ExceptionHandler(value = Exception.class)
public ModelAndView exceptionHandle(RedirectAttributes redirectAttributes) {
    ModelAndView modelAndView = new ModelAndView("redirect:/systemError");
    redirectAttributes.addFlashAttribute("error", "錯(cuò)誤信息");
    return modelAndView;
}

2、重定向方法

@GetMapping("/systemError")
public ModelAndView systemError(@ModelAttribute("error") String error){
    ModelAndView modelAndView = new ModelAndView("error");
    modelAndView.addObject("error", error);
    return modelAndView;
}

springboot redirect 傳參問(wèn)題

眾所周知:

redirect表示重定向,相比于請(qǐng)求轉(zhuǎn)發(fā),無(wú)法將添加的參數(shù)繼續(xù)保留,傳遞給下一個(gè)處理對(duì)象,但springboot給我們提供了一個(gè)方法,redirectattributes的addflashattribute方法將參數(shù),即使通過(guò)重定向也能傳遞出去,底層原理使用的是緩存臨時(shí)保存 重定向所攜帶的參數(shù)

具體案例

controller

在這里插入圖片描述

前端

在這里插入圖片描述

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論