码迷,mamicode.com
首页 > 移动开发 > 详细

SpringMVC(七) RequestMapping 路径中带占位符的URL

时间:2018-12-01 18:21:49      阅读:183      评论:0      收藏:0      [点我收藏+]

标签:string   ble   copy   bsp   src   mvc   控制   class   ota   

使用方法:在@RequestMapping("/delete/{id}")中,通过{id}带入pathvariable,然后在方法中,通过@PathVariable("变量名称") Iteger id 的方式引入占位符。

 

控制器代码:

技术分享图片
package com.tiekui.springmvc.handlers;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class TestPathVariable {
    @RequestMapping("/testparam/{id}")
    public String test(@PathVariable("id") Integer id){
        System.out.println(id);
        return "success";
    }
}
技术分享图片

视图代码:

<a href="testparam/100">Test PathVariable</a>

SpringMVC(七) RequestMapping 路径中带占位符的URL

标签:string   ble   copy   bsp   src   mvc   控制   class   ota   

原文地址:https://www.cnblogs.com/yuyu666/p/10050041.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!