SpringMVC(十二) RequestMapping使用POJO作为参数
将一个普通的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作为参数的更多相关文章
- MyBatis基础入门《十二》删除数据 - @Param参数
MyBatis基础入门<十二>删除数据 - @Param参数 描述: 删除数据,这里使用了@Param这个注解,其实在代码中,不使用这个注解也可以的.只是为了学习这个@Param注解,为此 ...
- c++11-17 模板核心知识(十二)—— 模板的模板参数 Template Template Parameters
概念 举例 模板的模板参数的参数匹配 Template Template Argument Matching 解决办法一 解决办法二 概念 一个模板的参数是模板类型. 举例 在c++11-17 模板核 ...
- SpringMVC(十二):SpringMVC 处理输出模型数据之@ModelAttribute
Spring MVC提供了以下几种途径输出模型数据:1)ModelAndView:处理方法返回值类型为ModelAndView时,方法体即可通过该对象添加模型数据:2)Map及Model:处理方法入参 ...
- SpringMVC(十五) RequestMapping map模型数据
控制器中使用map模型数据,传送数据给视图. 控制器参考代码: package com.tiekui.springmvc.handlers; import java.util.Arrays; impo ...
- SpringMVC(十四) RequestMapping ModelAndView
ModelAndView返回模型数据和视图.参考以下Demo代码,了解其实现方法.关注通过视图名称创建ModelAndView的构造方法,以及通过${requestScope.attribute}的方 ...
- 【C语言的日常实践(十二)】命令行参数
C计划main函数有两个参数.文章1一个通常被称为argc,它代表的命令行参数的个数. 第2个通常称为argv.它指向一组參数值. 指针数组:这个数组的每一个元素都是一个字符指针,数组的末尾是一个NU ...
- pytest十二:cmd命令行参数
命令行参数是根据命令行选项将不同的值传递给测试函数,比如平常在 cmd 执行”pytest —html=report.html”,这里面的”—html=report.html“就是从命令行传入的参数对 ...
- 【SpringMVC】---RequestMapping、Ant 路径、PathVariable 注解、HiddenHttpMethodFilter 过滤器、用 POJO 作为参数
一.web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi=&qu ...
- (转)SpringMVC学习(十二)——SpringMVC中的拦截器
http://blog.csdn.net/yerenyuan_pku/article/details/72567761 SpringMVC的处理器拦截器类似于Servlet开发中的过滤器Filter, ...
随机推荐
- clock gen sdk 代码笔记
int ClockConfig(void) { u32 DIVCLK_DIVIDE = 10; u32 CLKFBOUT_MULT = 53; u32 CLKFBOUT_FRAC = 625; u32 ...
- js----常用功能
切割 1. a="ddd" a.substr(0,1) 通过js找子代 document.getElementByClass("ddd").getElement ...
- 一道面试题 vuex缺点?
最近去面试的时候,面试官有一道题是让我阐述用vuex的优缺点,优点倒还好说,这个缺点还真没有认识到,有道友可以帮忙解惑嘛? 2 回答 慕标5265247 这种问题一般都有通用回答套路.一件挺好的东西, ...
- 论文阅读笔记七:Structure Inference Network:Object Detection Using Scene-Level Context and Instance-Level Relationships(CVPR2018)
结构推理网络:基于场景级与实例级目标检测 原文链接:https://arxiv.org/abs/1807.00119 代码链接:https://github.com/choasup/SIN Yong ...
- IDEA的debug操作
- 【第一部分】09Leetcode刷题
一.位1的个数 题目:191. Number of 1 Bits C++ Soution 1: class Solution { public: int hammingWeight(uint32_t ...
- Centos+Redis 集群
Redis 3.2.6集群搭建 Redis3.0版本之后支持Cluster. 1.1.redis cluster的现状 目前redis支持的cluster特性: 1):节点自动发现 2):slave- ...
- linux dig 命令使用方法
ref:https://www.imooc.com/article/26971?block_id=tuijian_wz dig 命令主要用来从 DNS 域名服务器查询主机地址信息. 查询单个域名的 D ...
- yarn的安装与使用及与npm对应的命令
在Nodejs环境下,通过npm install -g yarn 命令进行全局安装 例如:yarn versionyarn inityarn installyarn add vueyarn add v ...
- SQL Server中Text和varchar(max) 区别
SQL Server 2005之后版本:请使用 varchar(max).nvarchar(max) 和 varbinary(max) 数据类型,而不要使用 text.ntext 和 image 数据 ...