Home > Back-end >  About restful style for SpringMVC URL parameter of the problem
About restful style for SpringMVC URL parameter of the problem

Time:09-17

/* *
* this is the controller code url: http://localhost:8080/admin//dataModel/1
*/
@ RequestMapping ("/dataModel/{id} ")
Public String dataModel (Model Model, @ PathVariable Integer id (" id ")) {
Model. The addAttribute (" MSG ", "into the view layer data!" );
Return "/index. The JSP";
}
This is a JSP code
The ${MSG}

The ${id}


Why I'm here just can get id in front page ah I clearly without the id into the model also does not have the id in the field


Here if I use is normal? The stitching parameters, url: http://localhost:8080/admin//dataModel? Id=1 front page will take less than the value of id
The controller code is as follows:
@ RequestMapping ("/dataModel ")
Public String dataModel (Model Model, an Integer id) {
Model. The addAttribute (" MSG ", "into the view layer data!" );
Return "/index. The JSP";
}

In this way, can only take to the value of the MSG

CodePudding user response:

Is the model/1 or a model? Id=1 is just a form of mass data, need to discuss good before and after the end,
You that the server is accepting the model/1, to receive 1 as id directly, so there's no need to tell the back-end is this id,

CodePudding user response:

This is the parameter bindings, the springmvc framework features!
What are the specific types of way, to study!

CodePudding user response:

Mapping the @ GetMapping ("/user/${id} ")
Public ModelAndView userQuery2 (@ PathVariable (" id ") int id)

Go to http://localhost:8080/user/1.do
Reward 404
  • Related