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