4.Spring MVC @PathVariable注解

2017-05-15  本文已影响113人  765197250c12
package com.gu.controller;

import org.omg.CORBA.Request;
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;

/**
 * Created by gurongkang on 17/5/8.
 */
@Controller
@RequestMapping(value = "/controller")
public class HelloController {

  /**
   * @PathVariable可以用来映射URL的占位符到目标方法的参数中
   */
  @RequestMapping("/testPathVariable/{id}")
  public String testPathVariable(@PathVariable("id") Integer id) {
    System.out.printf("testPathVariable------>" + id);
    return "Hello";
  }
}

url测试

<a href="controller/testPathVariable/10">testPathVariable</a>

id 为10


源码 https://github.com/gurongkang/TestSpringMVC.git tag 3

上一篇 下一篇

猜你喜欢

热点阅读