SPRINGMVC (12) requestmapping using Pojo as a parameter

Source: Internet
Author: User

Pass in an ordinary Java class object as a parameter.

Pojo class Address:

 PackageCom.tiekui.springmvc.pojo; Public classAddress {PrivateString Province; PrivateString City;  PublicString getprovince () {returnProvince; }     Public voidsetprovince (String province) { This. Province =Province; }     PublicString getcity () {returnCity ; }     Public voidsetcity (String city) { This. City =City ; }}

Pojo class User:

 PackageCom.tiekui.springmvc.pojo; Public classUser {PrivateString username; PrivateString password; PrivateString Email; Private intAge ; Privateaddress address;  PublicString GetUserName () {returnusername; }     Public voidSetusername (String username) { This. Username =username; }     PublicString GetPassword () {returnpassword; }     Public voidSetPassword (String password) { This. Password =password; }     PublicString Getemail () {returnemail; }     Public voidsetemail (String email) { This. email =email; }     Public intGetage () {returnAge ; }     Public voidSetage (intAge ) {         This. Age =Age ; }     PublicAddress getaddress () {returnaddress; }     Public voidsetaddress (address address) { This. Address =address; } @Override PublicString toString () {return"User [username=" + Username + ", password=" + password + ", email=" + email + ", age=" + Age+ ", address=" + address + "]"; }    }

Controller code:

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

View Code:

    <formAction= "Testrequestpojo">Username:<inputtype= "username"name= "username">    <BR>Password:<inputtype= "Password"name= "Password">    <BR>Email:<inputtype= "text"name= "Email">    <BR>Age :<inputtype= "text"name= "Age">    <BR>Province:<inputtype= "text"name= "Address.province">    <BR>City :<inputtype= "text"name= "Address.city">    <BR>    <inputtype= "Submit"value= "Pojotest">    </form>

SPRINGMVC (12) requestmapping using Pojo as a parameter

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.