spring-mvc在jsp中,动态显示数据

spring-mvc在jsp中,动态显示数据,第1张

1 jsp中用¥{paramterName}接受数据

${announce}

2 发送参数方式

①用ModelMap

@RequestMapping("/user/login/page.do")
    public ModelAndView showLoginPage(ModelMap modelMap){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("user_login");
        modelMap.addAttribute("announce","tom");
        return modelAndView;
    }

②用HttpServiceRequest

@RequestMapping("/user/login/page.do")
    public String showLoginPage(HttpServletRequest request){
        request.setAttribute("announce","tom");
        return "user_login";
    }

③用ModelAndView

@RequestMapping("/user/login/page.do")
    public ModelAndView showLoginPage(){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("user_login");
        modelAndView.addObject("announce","tom");
        return modelAndView;
    }

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/801819.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-07
下一篇 2022-05-07

发表评论

登录后才能评论

评论列表(0条)

保存