@RequestMapping (value = "/detail", method = Requestmethod.get)
Public String Newdetail (@RequestParam (value= "id", defaultvalue= "1", required=true) int id, @RequestParam (value= " TypeId ", defaultvalue=" 2 ", required=true) int typeId) {
Newsinfoentity newsinfoentity = Newsinfoservice.findbyid (ID);
Newstypeentity newstypeentity = Newstypeservice.findbyid (typeId);
This.request.setAttribute ("Newsinfoentity", newsinfoentity);
This.request.setAttribute ("Newstypeentity", newstypeentity);
return "News_detail";
}
First of all, SPRINGMVC. The default supported binding types are:
Httpservletreequest object: Parameter information can be obtained from the request object
HttpServletResponse object: The response information can be processed by the response object
HttpSession object: Gets the object stored in the session
Model/modelmap:model is an interface, MODELMAP is an implementation of an interface. The role is to populate the model data into the request domain.
Parameter bindings for simple types:
1. Define a variable directly in the controller, but there is a restriction that the parameter names and parameters in the request must be consistent, otherwise the data will not be received.
For example:
controller:public void Controllertest (Integer id) {}
request:http://localhost:8080/springmvctest/controllertest?id=2; It must be written as "id=2" and not as "id". This property name is immutable.
2, using @requestparam for parameter binding, when using this annotation to bind, the parameter name does not need to be consistent with the parameter name in the request.
For example:
controller:public void Controllertest (@RequestParam (value= "id") Integer goods_id) {}
The @RequestParam (value= "id") Integer goods_id indicates that the id attribute in the request is bound to the goods_id parameter
request:http://localhost:8080/springdemo/controllertest?id=2; The parameter passed in here is named ID
In @requestparam, there is a property called Required @RequestParam (Required=true) that indicates that the current parameter must be passed in
@RequestParam also has a property called DefaultValue to indicate the default value @RequestParam (defaultvalue= "AAA"), you know not to do more introduction
3, the Pojo binding
Parameters of the Pojo type can be directly defined in the controller to receive data from the request.
The condition of this usage is that the value of the name attribute of input in the page must correspond to the Pojo property one by one!
Spring MVC binding parameter According to default, whether it must be passed, (Requestparam (value= "id", defaultvalue= "1", required=true))