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>
  • 相关阅读:
    第二阶段~JS中的各种循环语句
    项目一~达人美食图册详情
    项目一~达人行程
    项目一~美食达人图册
    项目一~机票2
    项目一~达人首页
    项目一~Hotel5
    pythonday02基础与运算符
    pythonday01计算机初步认识
    第六章 百度Apollo ROS介绍(2)
  • 原文地址:https://www.cnblogs.com/yy3b2007com/p/8193671.html
Copyright © 2011-2022 走看看