zoukankan      html  css  js  c++  java
  • SpringMVC(三):@RequestMapping中的URL中设定通配符,可以使用@PathVariable映射URL绑定的占位符

    1)带占位符的URL是Spring3.0新增的功能,该功能在SpringMVC向REST目标挺进发展过程中具有里程碑的意义。

    2)通过@PathVariable可以将URL中占位符参数绑定到控制器处理方法的入参中:URL中的{xxx}占位符可以通过@PathVariable("xxx")绑定到操作方法的入参中。

     在HelloWord.java中添加testPathVariable方法:

    package com.dx.springlearn.handlers;
    
    import org.springframework.stereotype.Controller;
    import org.springframework.web.bind.annotation.PathVariable;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RequestMethod;
    
    @Controller
    @RequestMapping("class_requestmapping")
    public class HelloWord {
        private static String SUCCESS = "success";
    
        @RequestMapping("/testPathVariable/{id}")
        public String testPathVariable(@PathVariable(value = "id", required = true) Integer id) {
            System.out.println("testPathVariable: id: " + id);
            return SUCCESS;
        }
    }

    index.jsp添加链接:

    <a href="class_requestmapping/testPathVariable/1">testPathVariable</a>
        <br>
  • 相关阅读:
    git 入门操作
    ubuntu apc 安装
    vps mysql自动关闭
    xdebug安装
    C#获取IP和主机名
    C#在类中用调用Form的方法
    luogu3181 [HAOI2016]找相同字符
    luogu6139 【模板】广义后缀自动机(广义SAM)
    广义后缀自动机小结
    Codeforces Round #620 (Div. 2) 题解
  • 原文地址:https://www.cnblogs.com/yy3b2007com/p/8193671.html
Copyright © 2011-2022 走看看