springboot-springmvc-requestParam
生活随笔
收集整理的這篇文章主要介紹了
springboot-springmvc-requestParam
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
springmvc請求方式
1、直接寫在形參中:基本類型
@RequestMapping("/testRequestParam1")
public ModelAndView testRequestParam1(String name) {ModelAndView mv = new ModelAndView();System.out.println(name);mv.setViewName("helloworld");return mv;
}
?
2、直接寫在形參中:pojo
/*** 頁面請求實例:* <form action="http://localhost:8080/hello/testRequestParam4" method="post">* <input type="text" name="id"/> <input type="text" name="name"/>* <input type="submit" value="提交"/> </form>*/
@RequestMapping("/testRequestParam4")
public ModelAndView testRequestParam4(T1 t) {System.out.println(t.getId());ModelAndView mv = new ModelAndView();mv.setViewName("helloworld");return mv;
}
3、通過@RequestParam寫在形參中
@RequestMapping("/testRequestParam2")
public ModelAndView testRequestParam2(@RequestParam(value = "id") Integer id) {ModelAndView mv = new ModelAndView();System.out.println(id);mv.setViewName("helloworld");return mv;
}
4、通過@PathVariable寫在形參中
@RequestMapping("/testRequestParam3/{id}")
public ModelAndView testRequestParam3(@PathVariable("id") Integer id) {ModelAndView mv = new ModelAndView();System.out.println(id);mv.setViewName("helloworld");return mv;
}
轉載于:https://www.cnblogs.com/lichangyunnianxue/p/9777325.html
總結
以上是生活随笔為你收集整理的springboot-springmvc-requestParam的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 轩辕剑 天之痕 是谁画的呢?
- 下一篇: 赵文卓演黄飞鸿穿越到现在(还有霍元甲,陈