zoukankan      html  css  js  c++  java
  • 008 使用POJO对象绑定请求参数

    1.介绍

      

    2.Person.java

     1 package com.spring.bean;
     2 
     3 public class Person {
     4     private String username;
     5     private String password;
     6     private String email;
     7     private int age;
     8     private Address address;
     9     
    10     public Person() {}
    11     public Person(String username, String password, String email, int agem,Address address) {
    12         super();
    13         this.username = username;
    14         this.password = password;
    15         this.email = email;
    16         this.age = age;
    17         this.address = address;
    18     }
    19     public String getUsername() {
    20         return username;
    21     }
    22     public void setUsername(String username) {
    23         this.username = username;
    24     }
    25     public String getPassword() {
    26         return password;
    27     }
    28     public void setPassword(String password) {
    29         this.password = password;
    30     }
    31     public String getEmail() {
    32         return email;
    33     }
    34     public void setEmail(String email) {
    35         this.email = email;
    36     }
    37     public int getAge() {
    38         return age;
    39     }
    40     public void setAge(int age) {
    41         this.age = age;
    42     }
    43     public Address getAddress() {
    44         return address;
    45     }
    46     public void setAddress(Address address) {
    47         this.address = address;
    48     }
    49     @Override
    50     public String toString() {
    51         return "Person [username=" + username + ", password=" + password + ", email=" + email + ", age=" + age
    52                 + ", address=" + address + "]";
    53     }
    54     
    55 }

    3.address.java

     1 package com.spring.bean;
     2 
     3 /**
     4  * 为了验证级联属性做的bean
     5  * @author dell
     6  *
     7  */
     8 public class Address {
     9     private String province;
    10     private String city;
    11     public Address() {}
    12     public Address(String province, String city) {
    13         super();
    14         this.province = province;
    15         this.city = city;
    16     }
    17     public String getProvince() {
    18         return province;
    19     }
    20     public void setProvince(String province) {
    21         this.province = province;
    22     }
    23     public String getCity() {
    24         return city;
    25     }
    26     public void setCity(String city) {
    27         this.city = city;
    28     }
    29     @Override
    30     public String toString() {
    31         return "Address [province=" + province + ", city=" + city + "]";
    32     }
    33     
    34 }

    4.controller

     1 package com.spring.it;
     2 
     3 import org.springframework.stereotype.Controller;
     4 import org.springframework.web.bind.annotation.CookieValue;
     5 import org.springframework.web.bind.annotation.RequestMapping;
     6 
     7 import com.spring.bean.Person;
     8 
     9 @Controller
    10 public class RequestParamControl {
    11     @RequestMapping("/pojo")
    12     public String hello(Person person) 
    13     {
    14         System.out.println("person="+person);
    15         return "success";
    16     }
    17 }

    5.index.jsp

     1 <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
     2     pageEncoding="ISO-8859-1"%>
     3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
     4 <html>
     5 <head>
     6 <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
     7 <title>Insert title here</title>
     8 </head>
     9 <body>
    10     <form action="pojo/" method="post">
    11         username:<input type="text" name="username"/>
    12         <br>
    13         passwaord:<input type="password" name="password"/>
    14         <br>
    15         email:<input type="text" name="email"/>
    16         <br>
    17         age:<input type="text" name="age"/>
    18         <br>
    19         province:<input type="text" name="address.province">
    20         <br>
    21         city:<input type="text" name="address.city">
    22         <br>
    23         <input type="submit" value="submit"/>
    24     </form>
    25 </body>
    26 </html>

    6.效果

      

      

  • 相关阅读:
    从发布订阅模式到redux(一)
    swipper的一个小坑
    代码精进之路读后感(二)
    代码精进之路读后感(一)
    编译提示没有对应的构造函数
    静态成员函数里面不能使用非静态的成员变量
    越精简越好
    MediaTypeListWidget->insertItem 添加的label没有填充单元格
    避免代码后期过分改动的方法
    Qt的index 用方法static_cast<CTableItem*>(index.internalPointer())取出来的值的成员都未初始化
  • 原文地址:https://www.cnblogs.com/juncaoit/p/8419848.html
Copyright © 2011-2022 走看看