将一个普通的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. linux之ab压力测试工具

    等待... https://www.cnblogs.com/myvic/p/7703973.html

  2. LeetCode(73):矩阵置零

    Medium! 题目描述: 给定一个 m x n 的矩阵,如果一个元素为 0,则将其所在行和列的所有元素都设为 0.请使用原地算法. 示例 1: 输入: [   [1,1,1],   [1,0,1], ...

  3. django----图书管理

    待完成 from django.db import models # Create your models here. class Book(models.Model): nid = models.A ...

  4. poj2411 状态压缩-铺地板题型-轮廓线解法(最优)

    解法参考博客https://blog.csdn.net/u013480600/article/details/19569291 一种做法是先打出所有的状态,即满足上下配对的所有可能方案,然后再逐行进行 ...

  5. bzoj1195 神奇的ac自动机+状态压缩dp

    /* 难的不是ac自动机,是状态压缩dp 之前做了一两题类似题目,感觉理解的还不够透彻 */ #include<iostream> #include<cstdio> #incl ...

  6. Centos6.10部署TeamViewer

    1.在官网下载支持Linux系统的包,建议下载TeamViewer12的包,官网URL:https://www.teamviewer.com/cn/download/linux/ 2.将下载的软件包导 ...

  7. sass编写高质量的css---(基础语法结构)

    一:基础1.Sass:最早也是最成熟的CSS预处理语言2.Less:兼容CSS的最流行的css预处理语言3.Stylus:主要用于node.js社区 二:scss写法1)混入@mixin alert( ...

  8. unzip文件解压

    1.记录下,遇到.zip的安装包,指定解压到某个地方 格式:unzip      压缩包名.zip  -d   存放路径  

  9. java运行环境增加字体

    背景 今天在使用jfreeChart时,显示中文乱码,如下图: 环境:Ubuntu 13.04 64bit  java7  tomcat 7.0.42 解决方法--增加系统字体 0. 安装环境包 su ...

  10. 步步為營-97-MyMVC3

    說明: 解決另外一個不合理之處:通過控制器完成處理 1:在mvc文件夾下面添加一個工廠類文件DefaultControllerFactory 1.2進一步升級為抽象工廠 2 下一步如何規範Contro ...