SpringMVC的controller方法上若需要参数 如User
Bean:
public class User {
private String name;
private String password;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
Controller代码:
@RequestMapping("addUser")
public String addUser(User user){
userServiceImp.addUser(user);
System.out.println("---------------------------------");
return "success";
}
表单代码:
<p>添加用户</p>
<form action="addUser.do" method="post">
userName:<input type="text" name="name"/><br/>
password:<input type="text" name="password">
<input type="submit"/>
</form>
只需将对象的属性名和input的name值匹配即可。
SpringMVC的controller方法上若需要参数 如User的更多相关文章
- SpringMVC基础-controller方法中的参数注解
@PathVariable 映射 URL 绑定的占位符 带占位符的 URL 是 Spring3.0 新增的功能,该功能在 SpringMVC 向 REST 目标挺进发展过程中具有里程碑的意义 通过 ...
- SpringMVC的Controller方法的参数不能直接绑定List、Set、Map
List需要绑定在对象上,而不能直接写在Controller方法的参数中. http://www.iteye.com/topic/973918
- springmvc中Controller方法的返回值
1.1 返回ModelAndView controller方法中定义ModelAndView对象并返回,对象中可添加model数据.指定view. 1.2 返回void 在controller方法形参 ...
- SpringMVC的controller方法中注解方式传List参数使用@RequestBody
在SpringMVC控制器方法中使用注解方式传List类型的参数时,要使用@RequestBody注解而不是@RequestParam注解: //创建文件夹 @RequestMapping(value ...
- SpringMVC中 controller方法返回值
1)ModelAndView @RequestMapping(value="/itemEdit") public ModelAndView itemEdit(){ //创建模型视图 ...
- SpringMVC学习记录五——功能开发及参数处理
15 包装类型pojo参数绑定 15.1 需求 商品查询controller方法中实现商品查询条件传入. 15.2 实现方法 第一种方法:在形参中 添加HttpServ ...
- springMVC中controller的传参的几种案例
1.springmvc的controller方法不指定method时,默认get/post都支持 //@RequestMapping(value="test") //@Reques ...
- 使用getParameterMap()方法实现对请求参数的封装的工具类
我们知道,HttpServletRequest这个类的getParameter(name),getParameterValues(name)可以分别实现对页面传来的单个参数和对多个同名参数的接受.特别 ...
- SpringMVC入门(二)—— 参数的传递、Controller方法返回值、json数据交互、异常处理、图片上传、拦截器
一.参数的传递 1.简单的参数传递 /* @RequestParam用法:入参名字与方法名参数名不一致时使用{ * value:传入的参数名,required:是否必填,defaultValue:默认 ...
随机推荐
- spring+ibatis整合
一.pom.xml: <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://ww ...
- openlayers优化项
做了一个简单的样式,但是做的不怎么样:希望和大家讨论下载动态图那里,怎么能够提高效率,提高数据,能够快速反应:一般的处理方法是什么?
- php utf-8字符转ascii字符
function utf8_urldecode($str) { $str = preg_replace("/%u([0-9a-f]{3,4})/i","&#x\\ ...
- 常用的.Net 知识点
1.Replace C#:(using System.Text.RegularExpressions;) string txt = Regex.Replace(txtLog.Text.ToString ...
- 组合or继承
面向对象设计有一个原则“优先使用对象组合,而不是继承”. 下面是两者优缺点的比较: 组 合 关 系 继 承 关 系 优点:不破坏封装,整体类与局部类之间松耦合,彼此相对独立 缺点:破坏封装,子类与父类 ...
- java.io.file
package cn.edu.tongji.cims.wade.system; import java.io.*; public class FileOperate { pub ...
- 慕课网-Java入门第一季-6-10 练习题
来源:http://www.imooc.com/ceping/1596 以下关于二维数组的定义和访问正确的是() A int[ ][ ] num = new int[ ][ ]; B int[ ][ ...
- adb server无法终止问题
这两天通过python去连接Android手机时,一直提示:Adb connection Error:An existing connection was forcibly closed by the ...
- 虚拟机下linux安装mysql,apache和php
由于腿伤了,卧床在家折腾下linux,尝试用虚拟机装mysql,apche和php.中间各种波折,装了好几天,觉得有些经验还是要记录下来,让自己别忘了:) 按照下面这篇文章的方法,基本可以顺利安装成功 ...
- 再议C风格变量声明
NeoRAGEx2002曾经有一篇文章提到这个问题,但是有很多内容并没有包括,例如const和__declspec. 最近我遇到一些这方面的问题,感觉有必要做一个系统性的总结.后来经过一些实验,得出了 ...