承接一二章
结构
index.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Hello World</title>
<br> <br>
<form action="springMVC/testPojo" method="get">
<input type="text" name="username"/>
<input type="text" name="password"/>
<input type="text" name="adress.province"/>
<input type="text" name="adress.city"/>
<input type="submit" value="submit"/>
</form>
</body>
</html>
Adress.java
package com.hdxy.pojo; public class Adress { private String province; private String city; @Override public String toString() { return "Adress [province=" + province + ", city=" + 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; } }
User.java
package com.hdxy.pojo; public class User { private String username; private String password; private Adress adress; @Override public String toString() { return "User [username=" + username + ", password=" + password + ", adress=" + adress + "]"; } 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 Adress getAdress() { return adress; } public void setAdress(Adress adress) { this.adress = adress; } }
test.java
package com.hdxy.domian; import java.lang.reflect.Method; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.CookieValue; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import com.hdxy.pojo.User; @RequestMapping("springMVC") @Controller public class Test { final public String SUCCESS="loginSuccess"; @RequestMapping(value="/testPojo") public String test(User user){ System.out.println("testRequestParam:"+user); return SUCCESS; } }