SPRINGMVC Study Notes (iii) using SERVLETAPI and entities as parameters

Source: Internet
Author: User

1.1. Using entity classes to receive request parameters

Spring MVC automatically fills the property values for the object by the request parameter name and the entity class property name. Cascading properties are supported.

@RequestMapping ("/pojoparams") public String pojoparams (user user) {System.out.println (user); return "HelloWorld";}

User.java:

Package Com.ibigsea.springmvc.model;import Java.io.serializable;public class User implements Serializable {private Static final Long Serialversionuid = -5975751076183659876l;private String name;private int age;private Department DEPARTM Ent;public String GetName () {return name;} public void SetName (String name) {this.name = name;} public int getage () {return age;} public void Setage (int.) {this.age = age;} Public Department getdepartment () {return Department;} public void Setdepartment (Department Department) {this.department = Department;} @Overridepublic String toString () {return "User [name=" + name + ", age=" + Age + ", department=" + department + "]";}}

Department.java:

Package Com.ibigsea.springmvc.model;import Java.io.serializable;public class Department implements Serializable { Private static final Long Serialversionuid = 6881984318733090395l;private integer id;private String name;public integer ge TId () {return ID;} public void SetId (Integer id) {this.id = ID;} Public String GetName () {return name;} public void SetName (String name) {this.name = name;} @Overridepublic String toString () {return "Department [id=" + ID + ", name=" + name + "]";}}

Jsp:

Operation result :

User [Name=bigsea, age=23, department=department [Id=1, Name=test]]












1.2. Servletapias a request parameter
@RequestMapping ("/servletapi") public String Servletapi (httpservletrequest request,httpservletresponse response, HttpSession session) {System.out.println ("Servletapi"); return "HelloWorld";}


From the source can be known SPIRNGMVC support 9 kinds of parameters

Javax.servlet.ServletRequest

Javax.servlet.ServletResponse

Javax.servlet.http.HttpSession

Java.security.Principal

Java.util.Locale

Java.io.InputStream

Java.io.Reader

Java.io.OutputStream

Java.io.Writer
















SPRINGMVC Study Notes (iii) using SERVLETAPI and entities as parameters

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.