SpringMVC如何获取查询参数及路径参数

发布时间:2021-09-27 17:50 来源:亿速云 阅读:0 作者:小新 栏目: 开发技术

这篇文章将为大家详细讲解有关SpringMVC如何获取查询参数及路径参数,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。

Jsp页面 query.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %><%@ page isELIgnored="false" %><html><head>  <title>Title</title></head><body>  <h2>您输入的id是 ${id}</h2></body></html>
@RequestParm获取查询参数
@Controller@RequestMapping("/test")public class TestController {  @RequestMapping(value = "/user", method = RequestMethod.GET)  public String user(@RequestParam("id") int id, Map<String, Integer> map) {    map.put("id", id);    return "query";  }}

以上可访问.../test/user?id=10测试

@PathVariable获取路径参数
@Controllerpublic class TestController {  @RequestMapping(value = "/user/{id}", method = RequestMethod.GET)  public String user(@PathVariable("id") int id, Map<String, Integer> map) {    map.put("id", id);    return "query";  }}

以上可访问.../user/10测试

免责声明:本站发布的内容(图片、视频和文字)以原创、来自互联网转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系QQ:712375056 进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。