首页 >

SpringMvc接收参数

Java|java教程SpringMvc接收参数
SpringMvc,参数,接收
Java-java教程
电商文章网站源码,vscode同时修改多行,ubuntu卡死花屏,查看tomcat类加载,sqlite3连接查询,爬虫是不是还得学习网页数据加密,php 变负数,江门seo外包 分化.net,在线视频教育网站源码,discuz x3 免费模板lzw
接收参数的方式:
1.HttpServletRequest方式接收
public ModelAndView test1(HttpServletRequest req){
String userName = req.getParameter(“userName”);
String password = req.getParameter(“password”);
System.out.println(userName);
System.out.println(password);
return new ModelAndView(“jsp/hello”);
}
2.@RequestParam方式
public ModelAndView test2(String userName,
@RequestParam(“password”) String pwd){
System.out.println(userName+”,”+pwd);
return new ModelAndView(“jsp/hello”);
}
3.对象的方式接收
public ModelAndView test3(User user){
System.out.println(user);
return new ModelAndView(“jsp/hello”);
}
4.
/**
* 使用ModelAndView传出参数 内部 HttpServletRequest的Attribute传递 到jsp页面
   * ModelAndView(String viewName,Map data)data是处理结果
*/
@RequestMapping(“action”)
public ModelAndView test4(User user){
Map data = new HashMap();
data.put(“user”, user);
return new ModelAndView(“jsp/hello”,data);
}
5. Session的方式
/**
* session存储 可以使用HttpServletRequest的getSession方法访问
*/
@RequestMapping(“action”)
public ModelAndView test7(HttpServletRequest req){
HttpSession session = req.getSession();
session.setAttribute(“salary”, 6000.0);
return new ModelAndView(“jsp/hello”);
}
6.重定向:
@RequestMapping(“/updateitem”)
//spirngMvc可以直接接收pojo类型:要求页面上input框的name属性名称必须等于pojo的属性名称
public ModelAndView updateitem(Items items){
itemsService.updateitems(items);
//不可以加斜杠 解析不了 itemList.action
return new ModelAndView(new RedirectView(“itemList.action”));
}
7.重定向
@RequestMapping(“/updateitem”)
//spirngMvc可以直接接收pojo类型:要求页面上input框的name属性名称必须等于pojo的属性名称
public String updateitem(Items items){
itemsService.updateitems(items);
//重定向到action 可以加斜杠 redirect:/itemList.action 解析的了
return “redirect:itemList.action”;
}

使用Model和ModelMap的效果一样,如果直接使用Model,springmvc会实例化ModelMap。

填报 系统源码,怎么验证ubuntu镜像,两个tomcat共用一个文件,python 爬虫实现替换,php程序区分哪个用户下的单,兰州seo基础lzw
如果使用Model则可以不使用ModelAndView对象,Model对象可以向页面传递数据,View对象则可以使用String返回值替代。不管是Model还是ModelAndView,其本质都是使用Request对象向jsp传递数据。
h5棋牌源码下载,vscode安装教程c语言,ubuntu.驱动,tomcat安装时出错,爬虫技术讨论,链家 php,seo的产品有什么好处,装修公司网站html模板,wordpress 金融 模板下载lzw

SpringMvc接收参数
  • struts2和springMVC的区别是什么
  • struts2和springMVC的区别是什么 | struts2和springMVC的区别是什么 ...

    SpringMvc接收参数
  • SpringMvc文件上传
  • SpringMvc文件上传 | SpringMvc文件上传 ...

    SpringMvc接收参数
  • springmvc常用注解有哪些?
  • springmvc常用注解有哪些? | springmvc常用注解有哪些? ...