码迷,mamicode.com
首页 > 编程语言 > 详细

springMVC---级联属性

时间:2018-01-01 17:01:13      阅读:191      评论:0      收藏:0      [点我收藏+]

标签:param   page   pojo   html4   res   alt   http   结构   eva   

承接一二章

结构

技术分享图片

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;
   }
}

 

springMVC---级联属性

标签:param   page   pojo   html4   res   alt   http   结构   eva   

原文地址:https://www.cnblogs.com/lnthz/p/8167400.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!