首页 > 编程语言 > 详细

springboot-springmvc-requestParam

时间:2018-10-12 13:32:46      阅读:210      评论:0      收藏:0      [点我收藏+]

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;
}

  

springboot-springmvc-requestParam

原文:https://www.cnblogs.com/lichangyunnianxue/p/9777325.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!