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

CodePudding user response:

refer to the original poster eisldkw response:
the same method queryList can have two kinds of parameters, the code is 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 [/color]



Method parameters is needed when the class instantiation is certain, the different methods with the same parameters this is very normal, because the parameters are essentially/queryList this page, just extract the data parameter types are different,

CodePudding user response:

For example you from obtaining a value of 10, you can take 10 as int parameter, also can be in the 10 as a String parameter,

CodePudding user response:

refer to the second floor qq_39936465 response:
for example you from obtaining a value of 10, you can take 10 as int parameter, also can be in the 10 as a String parameter,


Thank you very much, but you're too young,

CodePudding user response:

reference eisldkw reply: 3/f
Quote: refer to the second floor qq_39936465 response:
for example you from obtaining a value of 10, you can take 10 as int parameter, also can be in the 10 as a String parameter,


Thank you very much, but you're too young,



Just for example, many of them are now have a framework to achieve, if the source code and you will see that the underlying implementation methods are the same, but is the set of ma3 jia3,

CodePudding user response:

You can also use to write their own class interface, to realize the data transmission, don't be fooled by appearances, essence is the method parameter, there is nothing very deep,

CodePudding user response:

refer to the second floor qq_39936465 response:
for example you from obtaining a value of 10, you can take 10 as int parameter, also can be in the 10 as a String parameter,


Thank you very much,

CodePudding user response:

The abnormal transactions, same @ RequestMapping (value="https://bbs.csdn.net/queryList") Error creating requestMappingHandlerMapping

CodePudding user response:

refer to the second floor qq_39936465 response:
for example you from obtaining a value of 10, you can take 10 as int parameter, also can be in the 10 as a String parameter,


Thank you very much, could you please tell me, is this queryList parameters in (Model Model, Fruit, Fruit, it request, HttpServletResponse response) is, in fact, the four parameters have?

CodePudding user response:

refer to the eighth floor eisldkw response:
Quote: refer to the second floor qq_39936465 response:
for example you from obtaining a value of 10, you can take 10 as int parameter, also can be in the 10 as a String parameter,


Thank you very much, could you please tell me, is this queryList parameters in (Model Model, Fruit, Fruit, it request, HttpServletResponse response) is, in fact, the four parameters have?


Model is a Model class, in your case you can understand as the/queryList page it and the data of HttpServletResponse, encapsulated in the Model type generated in a particular bean convenient you use, of course you also can call directly with Java to use it directly, so that you can choose to use,

CodePudding user response:

references 9 f qq_39936465 response:
Quote: refer to the eighth floor eisldkw response:
Quote: refer to the second floor qq_39936465 response:
for example you from obtaining a value of 10, you can either take 10 as int parameter, also can be in the 10 as a String parameter,


Thank you very much, could you please tell me, is this queryList parameters in (Model Model, Fruit, Fruit, it request, HttpServletResponse response) is, in fact, the four parameters have?


Model is a Model class, in your case you can understand as the/queryList page it and the data of HttpServletResponse, encapsulated in the Model type generated in a particular bean convenient you use, of course you also can call directly with Java to use it directly, so that you can choose to use,


Thank you very much, can you tell me what is the model class?

CodePudding user response:

Springboot parameter parser to learn, you can baidu spring after the start will help us to register the parser, a bunch of parameters such as:
The method of RequestMappingHandlerAdapter class
 
Private List GetDefaultArgumentResolvers () {
List Resolvers=new ArrayList ();
Resolvers. Add (new RequestParamMethodArgumentResolver (enclosing getBeanFactory (), false));
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related