@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 @   yulinna02  阅读(167)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· winform 绘制太阳,地球,月球 运作规律
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)
点击右上角即可分享
微信分享提示