java 域?qū)ο蠊蚕頂?shù)據(jù)的實(shí)現(xiàn)
域?qū)ο蠊蚕頂?shù)據(jù)
使用ServletAPI向request域?qū)ο蠊蚕頂?shù)據(jù)
@RequestMapping("/testServletAPI")
public String testServletAPI(HttpServletRequest request) {
request.setAttribute("key","value");
return "index";
}
使用ModelView向request域?qū)ο笾泄蚕頂?shù)據(jù)
@RequestMapping("/testModelAndView")
public ModelAndView testModelAndView(){
ModelAndView mv = new ModelAndView();
// 向請求域中共享數(shù)據(jù)
mv.addObject("key","value");
// 設(shè)置視圖,實(shí)現(xiàn)跳轉(zhuǎn)
mv.setViewName("index");
return mv;
}
使用Model向request域?qū)ο蠊蚕頂?shù)據(jù)
@RequestMapping("/testModel")
public String testModel(Model model) {
model.addAttribute("key","value");
return "index";
}
使用map向request域?qū)ο蠊蚕頂?shù)據(jù)
@RequestMapping("/testMap")
public String testMap(Map<String,Object> map) {
map.put("key","value");
return "index";
}
使用ModelMap向request域?qū)ο蠊蚕頂?shù)據(jù)
@RequestMapping("/testModelMap")
public String testModelMap(ModelMap modelMap) {
modelMap.addAttribute("key","value");
return "index";
}
ModelAndView、Model、Map、ModelMap傳遞數(shù)據(jù)時都是實(shí)例化org.springframework.validation.support.BindingAwareModelMap實(shí)現(xiàn)類
//DispatcherServlet源碼,將數(shù)據(jù)封裝的部分代碼 // Actually invoke the handler. mv = ha.handle(processedRequest, response, mappedHandler.getHandler());

向session域共享數(shù)據(jù)
@RequestMapping("/testSession")
public String testSession(HttpSession session){
session.setAttribute("key","value");
return "index";
}
向application域?qū)ο蠊蚕頂?shù)據(jù)
@RequestMapping("testApplication")
public String testApplication(HttpSession session){
ServletContext servletContext = session.getServletContext();
servletContext.setAttribute("key","value");
return "index";
}
到此這篇關(guān)于java 域?qū)ο蠊蚕頂?shù)據(jù)的實(shí)現(xiàn)的文章就介紹到這了,更多相關(guān)java 域?qū)ο蠊蚕頂?shù)據(jù)內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
在springboot項目中同時接收文件和多個參數(shù)的方法總結(jié)
在開發(fā)接口中,遇到了需要同時接收文件和多個參數(shù)的情況,可以有多種方式實(shí)現(xiàn)文件和參數(shù)的同時接收,文中給大家介紹了兩種實(shí)現(xiàn)方法,感興趣的同學(xué)跟著小編一起來看看吧2023-08-08
SpringBoot使用JWT實(shí)現(xiàn)登錄驗證的方法示例
這篇文章主要介紹了SpringBoot使用JWT實(shí)現(xiàn)登錄驗證的方法示例,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-06-06
java Arrays快速打印數(shù)組的數(shù)據(jù)元素列表案例
這篇文章主要介紹了java Arrays快速打印數(shù)組的數(shù)據(jù)元素列表案例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-09-09
解決Error:(5,55)java:程序包org.springframework.cloud.netflix.eure
這篇文章主要介紹了解決Error:(5,55)java:程序包org.springframework.cloud.netflix.eureka.server不存在問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2023-11-11
mybatis多數(shù)據(jù)源動態(tài)切換的完整步驟
這篇文章主要給大家介紹了關(guān)于mybatis多數(shù)據(jù)源動態(tài)切換的完整步驟,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-11-11
IDEA安裝lombok插件設(shè)置Enable Annotation Processing后編譯依然報錯解決方法
這篇文章主要介紹了IDEA安裝lombok插件設(shè)置Enable Annotation Processing后編譯依然報錯解決方法,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-04-04

