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

java 域?qū)ο蠊蚕頂?shù)據(jù)的實(shí)現(xiàn)

 更新時(shí)間:2023年03月27日 10:51:13   作者:卑微小鐘  
本文主要介紹了java 域?qū)ο蠊蚕頂?shù)據(jù)的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧

域?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();
    // 向請(qǐng)求域中共享數(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、MapModelMap傳遞數(shù)據(jù)時(shí)都是實(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)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論