Home > Back-end > The same method can be used for SPRINGMVC background controller two different parameters, for SPRING
The same method can be used for SPRINGMVC background controller two different parameters, for SPRING
Time:09-22
The same method queryList can have two kinds of parameters, the code is as follows:
A parameter binding: a wrapper class @ RequestMapping (value="https://bbs.csdn.net/queryList") Public String queryList ( Model Model, Fruit Fruit { )System. The out. Println (" name: "+ fruit. GetName ()); } Url: http://localhost:8080/SpringMVC_test/queryList.action? Name=% E5 A7 E6 A7 8 d % % % % % BD Output: Name: oh Name is Fruit wrapper class attribute name, this type will be for SpringMVC processor adapter parsing, will create a specific entity class, and the relevant attribute values through the set method is bound to the wrapper classes, so successful,
Two, was introduced into it and HttpServletResponse, such as: @ RequestMapping (value="https://bbs.csdn.net/queryList") Public String queryList ( it request, HttpServletResponse response { )System. The out. Println (" name: "+ request. The getParameter (" name")); Return "/fruitsList"; } Url: http://localhost:8080/SpringMVC_test/queryList.action? Name=% E5 A7 E6 A7 8 d % % % % % BD Output: * * * Name: oh
questions as follows:
Why the same method queryList, its parameters can be either it request, HttpServletResponse response and can be a Model Model, Fruit, Fruit, for SPRINGMVC to receive these two sets of parameters, is how to distinguish, how can you compare these parameters to the correct variable or object