Spring MVC接收参数的方式
来源:互联网 发布:淘宝开店未认证 编辑:程序博客网 时间:2024/05/22 09:11
第一种接收参数的方式:
1、com.venustech.entity.User实体类属性:
Integer id 、String username、String password
2、controller控制层
package com.venustech.controller;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.Mapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
import com.venustech.entity.User;
@Controller
@RequestMapping("/user")
public class UserAction {
@RequestMapping("/test")
public ModelAndView test2(User user){
ModelAndView mov=new ModelAndView();
mov.setViewName("hello");
mov.addObject("name", user.getUsername());
mov.addObject("password", user.getPassword());
mov.addObject("msg", "保存成功");
return mov;
}
}
只需要调用http://ip:port/项目名/user/test?username="se7en"&password="123"就可以传递参数
如果你传入的参数为user.username="se7en"反而还收不到了呢!
总结:1、spring MVC接收类对象时只需要写入对应类中的属性的名称对应的get方法
2、这里面的mov中的setViewName是对应的跳转的页面
addObject中的string 可以在跳转的页面中用${string}来获取。
第二种接收参数:
@RequestMapping("/test")
public ModelAndView test2(String username,String password)
{
ModelAndView mov=new ModelAndView();
mov.setViewName("hello");
mov.addObject("name", name);
mov.addObject("password", password);
mov.addObject("msg", "保存成功");
return mov;
}
注意:如果是用mov传递一个user对象的话页面上的接收方式为${requestScope.user.username}如果只是单纯的
${user.username}是没有用的。
第三中接收参数
@RequestMapping("/save")
public String test1(@RequestParam(required=true,defaultValue="18")String username,@RequestParam(required=false)String password){
System.out.println("name:"+name+"password:"+password);
//return "hello";// http://ip:端口/web应用/hello.jsp
return "redirect:/hello.jsp";
}
- Spring MVC接收参数的方式
- spring mvc 接收参数的方式总结
- Spring mvc 接收参数的几种方式
- Spring MVC参数的传递与接收
- Spring MVC中action接收从页面传递过来的参数方式
- Spring mvc 针对get 和 post 请求参数的不同接收方式
- spring mvc 接收时间参数
- spring mvc接收json参数
- Spring MVC 接收数组参数
- spring mvc 后台获取参数的方式
- Spring mvc 接受请求参数的方式
- spring MVC 的参数传递方式
- spring mvc 接收jquery ajax 提交的数组参数
- spring mvc控制层(controller)接收参数的问题
- Spring MVC 传入List参数的接收问题
- Spring MVC后台接收不到POST请求的参数
- Spring MVC无法接收PUT类请求参数的解决方案
- spring MVC不能直接接收list类型参数的问题
- Docker 容器真的安全么?
- jq仿京东图片放大效果
- iOS 瘦身ViewController 分离tableViewDataSource
- android实现背景音乐播放
- galera安装之编译安装xtrabackup 2.2.11
- Spring MVC接收参数的方式
- IOS创建控件的注意点
- EasyDarwin开源平台直播架构
- 测试
- 基于反射制作Ioc库(下)
- java.sql.SQLException: 关闭的连接 解决办法
- Maven指定文件上传远程仓库【非中央仓库】
- Unity3D Editor在右键弹出菜单中添加 item
- JAVA注解