springmvc controll与jsp数据显示

来源:互联网 发布:电脑编程代码大全 编辑:程序博客网 时间:2024/05/17 07:52

controll 层 返回jsp 页面,同时返回数据显示在jsp 里面

controll层有几种写法:

写法一:

@RequestMapping(value = "/addUser")
public String addUser(HttpServletRequest req, ModelMap model) {

String username = req.getParameter("username");
//设置返回到jsp的数据
model.put("result", "add ok");
return "login";
}

写法二:

@RequestMapping(value="/getdomain/{input}")
public String getDomain(@PathVariable("input") String input) {
 
ModelAndView modelandView = new ModelAndView();
modelandView.addObject("result", "111");
return "login";
}

写法三:

@RequestMapping(value="/getdomain/{input}")
publicModelAndView getDomain(@PathVariable("input") String input) {
 
ModelAndView modelandView = new ModelAndView(“login”);
modelandView.addObject("result", "111");
returnmodelandView
}


jsp页面获取数据方式

${result}

就可以显示了

0 0