将一个普通的JAVA类对象作为一个参数传入。

POJO类Address:

package com.tiekui.springmvc.pojo;

public class Address {
private String province;
private String city; public String getProvince() {
return province;
}
public void setProvince(String province) {
this.province = province;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
}

POJO类User:

package com.tiekui.springmvc.pojo;

public class User {
private String username;
private String password;
private String email;
private int age; private Address address; public String getUsername() {
return username;
} public void setUsername(String username) {
this.username = username;
} public String getPassword() {
return password;
} public void setPassword(String password) {
this.password = password;
} public String getEmail() {
return email;
} public void setEmail(String email) {
this.email = email;
} public int getAge() {
return age;
} public void setAge(int age) {
this.age = age;
} public Address getAddress() {
return address;
} public void setAddress(Address address) {
this.address = address;
} @Override
public String toString() {
return "User [username=" + username + ", password=" + password + ", email=" + email + ", age=" + age
+ ", address=" + address + "]";
} }

控制器代码:

package com.tiekui.springmvc.handlers;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping; import com.tiekui.springmvc.pojo.User; @Controller
public class RequestPOJO { @RequestMapping("testRequestPojo")
public String testRequestPojo(User user) {
System.out.println(user);
return "success";
}
}

视图代码:

    <form action="testRequestPojo">
username : <input type="username" name="username">
<br>
password : <input type="password" name="password">
<br>
email : <input type="text" name="email">
<br>
age : <input type="text" name="age">
<br>
province : <input type="text" name="address.province">
<br>
city : <input type="text" name="address.city">
<br>
<input type="submit" value="PojoTest">
</form>

SpringMVC(十二) RequestMapping使用POJO作为参数的更多相关文章

  1. MyBatis基础入门《十二》删除数据 - @Param参数

    MyBatis基础入门<十二>删除数据 - @Param参数 描述: 删除数据,这里使用了@Param这个注解,其实在代码中,不使用这个注解也可以的.只是为了学习这个@Param注解,为此 ...

  2. c++11-17 模板核心知识(十二)—— 模板的模板参数 Template Template Parameters

    概念 举例 模板的模板参数的参数匹配 Template Template Argument Matching 解决办法一 解决办法二 概念 一个模板的参数是模板类型. 举例 在c++11-17 模板核 ...

  3. SpringMVC(十二):SpringMVC 处理输出模型数据之@ModelAttribute

    Spring MVC提供了以下几种途径输出模型数据:1)ModelAndView:处理方法返回值类型为ModelAndView时,方法体即可通过该对象添加模型数据:2)Map及Model:处理方法入参 ...

  4. SpringMVC(十五) RequestMapping map模型数据

    控制器中使用map模型数据,传送数据给视图. 控制器参考代码: package com.tiekui.springmvc.handlers; import java.util.Arrays; impo ...

  5. SpringMVC(十四) RequestMapping ModelAndView

    ModelAndView返回模型数据和视图.参考以下Demo代码,了解其实现方法.关注通过视图名称创建ModelAndView的构造方法,以及通过${requestScope.attribute}的方 ...

  6. 【C语言的日常实践(十二)】命令行参数

    C计划main函数有两个参数.文章1一个通常被称为argc,它代表的命令行参数的个数. 第2个通常称为argv.它指向一组參数值. 指针数组:这个数组的每一个元素都是一个字符指针,数组的末尾是一个NU ...

  7. pytest十二:cmd命令行参数

    命令行参数是根据命令行选项将不同的值传递给测试函数,比如平常在 cmd 执行”pytest —html=report.html”,这里面的”—html=report.html“就是从命令行传入的参数对 ...

  8. 【SpringMVC】---RequestMapping、Ant 路径、PathVariable 注解、HiddenHttpMethodFilter 过滤器、用 POJO 作为参数

    一.web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi=&qu ...

  9. (转)SpringMVC学习(十二)——SpringMVC中的拦截器

    http://blog.csdn.net/yerenyuan_pku/article/details/72567761 SpringMVC的处理器拦截器类似于Servlet开发中的过滤器Filter, ...

随机推荐

  1. 【数据库】MySQL的左连接、右连接和全连接的实现

    表student:+----+-----------+------+| id | name | age |+----+-----------+------+| 1 | Jim | 18 || 2 | ...

  2. SpringBoot的yml配置文件

    1.在src\main\resources下创建application.yml配置文件 spring: datasource: driver-class-name: com.mysql.jdbc.Dr ...

  3. Metasploit渗透测试模块(一)

    1.Metasploit模块加载 初始化界面,成功要加载数据库 查看 Metasploit中已近存在的漏洞模块使用 show payloads

  4. codeforce 240E 最小树形图+路径记录更新

    最小树形图的路径是在不断建立新图的过程中更新的,因此需要开一个结构体cancle记录那些被更新的边,保存可能会被取消的边和边在旧图中的id 在朱刘算法最后添加了一个从后往前遍历新建边的循环,这可以理解 ...

  5. django的查看sql语句setting设置

    LOGGING = {     'version': 1,     'disable_existing_loggers': False,     'handlers': {         'cons ...

  6. typeof操作符--undefined与null

    <!DOCTYPE html><html><head> <meta charset="utf-8"> <title>ty ...

  7. 修改jenkins发布账号信息

  8. mysql optimize table

    mysql 数据文件的使用是只扩展,不回收.对表执行delete之后,磁盘上数据文件是不会缩小的. 通常的做法,是先逻辑导出,然后truncate 原表(或者删除重建),再导入. 另外还有一种方法是o ...

  9. Mysql 5.7 CentOS 7 安装MHA

    Table of Contents 1. MHA简介 1.1. 功能 1.2. MHA切换逻辑 1.3. 工具 2. 环境 2.1. 软件 2.2. 环境 3. Mysql 主从复制 3.1. Mys ...

  10. 论文阅读笔记十一:Rethinking Atrous Convolution for Semantic Image Segmentation(DeepLabv3)(CVPR2017)

    论文链接:https://blog.csdn.net/qq_34889607/article/details/8053642 摘要 该文重新窥探空洞卷积的神秘,在语义分割领域,空洞卷积是调整卷积核感受 ...