2015年11月17日 星期二

Spring MVC @RequestMapping 用法

1) Simple method mapping

@RequestMapping(value="/simpleMethod")

public void simpleMethod() {

    //simpleMethod() called

}

2) With parameter


@RequestMapping(value="/simpleMethod")

public void simpleMethod(@RequestParam("param") String param) {

    printLn("the new param = " + param);

}

3)REST style


@RequestMapping(value="/
simpleMethod/{param}")  
public void simpleMethod(@PathVariable  String param){  
  
    printLn("the new param = " + param);

}  

4)改變傳入的param名稱

@RequestMapping(value="/simpleMethod/{param}")  
public void simpleMethod(@PathVariable("param") String studentId){  
  
    printLn("the student id = " + studentId);  

}  
















沒有留言:

張貼留言