@PathVariable("id") String id和@RequestParam("name")String name

@PathVariable("id") String id

主要是从地址栏获取id

@RequestMapping("/hello/{id}")
public String hello(@PathVariable("id") String id,Map<Object,String> map){
log.info(id);
map.put("id",id);
return "hello";

}
localhost:8080/hello/5

<h1 th:text="${id}"></h1>


@RequestParam主要是获取表单提交的
<form action="/index" >
<input type="text" name="name">
<input type="submit">
</form>
<form action="/index2" >
<input type="text" name="number">
<input type="submit">
</form>

@RequestMapping("/index")
public ModelAndView index(@RequestParam("name")String name){
log.info(name);
ModelAndView modelAndView=new ModelAndView();
modelAndView.setViewName("test");
modelAndView.addObject("name",name);
return modelAndView;
}
@RequestMapping("/index2")
public String index2(@RequestParam("number")String number,Model model){
model.addAttribute("number","number");
log.info(number);
return "test";
}
posted @ 2022-07-13 11:12  yulinna02  阅读(163)  评论(0编辑  收藏  举报