springmvc使用pojo和servlet原生api作為參數

來源:互聯網
上載者:User

標籤:ons   package   get   map   put   string   test   type   tostring   

一、Pojo作為參數:

實體:

package com.hy.springmvc.entities;public class User {        private String username;        private String password;        private String email;        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 Address getAddress() { return address; } public void setAddress(Address address) { this.address = address; } @Override public String toString() { return "User [username=" + username + ", password=" + password + ", email=" + email + ", address=" + address + "]"; } }
package com.hy.springmvc.entities;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; } @Override public String toString() { return "Address [province=" + province + ", city=" + city + "]"; } }

 

註解方法:

@RequestMapping("/testPojo")    public String testPojo(User user) {        System.out.println("testPojo :"+user);        return SUCCESS;    }

頁面調用:

<form action="test/testPojo">    username:<input name="username" type="text"><br>    password:<input name="password" type="password"><br>    email:<input name="email" type="text"><br>    province:<input name="address.province" type="text"><br>    city:<input name="address.city" type="text"><br>    <input type="submit" value="submit"></form>

支援級聯屬性

 

二、使用servlet原生api作為參數:

springmvc可以在映射方法中使用:

HttpServletRequest,

HttpServletResponse,

Writer,

InputStrream,

OutPutStream,

Locale

等作為參數。。

springmvc使用pojo和servlet原生api作為參數

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.