/**
* 这是controller 代码 url :http://localhost:8080/admin//dataModel/1
*/
@RequestMapping("/dataModel/{id}")
public String dataModel(Model model, @PathVariable("id") Integer id){
model.addAttribute("msg","带入到视图层的数据!");
return "/index.jsp";
}
这是jsp代码
${msg}${id}
我这里只是为什么可以在前端页面中取到id啊 我明明没有将id存入到model 也没有将id存入域里
我这里如果用的是普通的?后面拼接参数的话, url :http://localhost:8080/admin//dataModel?id=1 前端页面就取不到id的值
controller代码如下:
@RequestMapping("/dataModel")
public String dataModel(Model model, Integer id){
model.addAttribute("msg","带入到视图层的数据!");
return "/index.jsp";
}这样的话,就只能取到msg的值
* 这是controller 代码 url :http://localhost:8080/admin//dataModel/1
*/
@RequestMapping("/dataModel/{id}")
public String dataModel(Model model, @PathVariable("id") Integer id){
model.addAttribute("msg","带入到视图层的数据!");
return "/index.jsp";
}
这是jsp代码
${msg}${id}
我这里只是为什么可以在前端页面中取到id啊 我明明没有将id存入到model 也没有将id存入域里
我这里如果用的是普通的?后面拼接参数的话, url :http://localhost:8080/admin//dataModel?id=1 前端页面就取不到id的值
controller代码如下:
@RequestMapping("/dataModel")
public String dataModel(Model model, Integer id){
model.addAttribute("msg","带入到视图层的数据!");
return "/index.jsp";
}这样的话,就只能取到msg的值
你那个服务器端就是接受model/1的,接收到1就直接当成id用了,所以不需要告诉后端这是id。
具体有哪几种方式,自行研究吧!