sping入门

SpringMVC

1、RequestMapping 处理地址映射请求

    参数: value, produces, method, params, headers

    value:指定请求的实际地址

    1、最基本

@RequestMapping(value="/departments")  
public String simplePattern(){  
  
    System.out.println("simplePattern method was called");  
    return "someResult";  
}

  通过访问 http://localhost:8080/***/departments,可以进入函数

  2、绑定参数

    @RequestMapping(value="/departments")  
    public String findDepatment(  
      @RequestParam("departmentId") String departmentId){  
        
        System.out.println("Find department with ID: " + departmentId);  
        return "someResult";  
      
    }  

 
  形如这样的访问形式:
   /departments?departmentId=23就可以触发访问findDepatment方法了

3 REST风格参数

RequestMapping(value="/departments/{departmentId}")  
public String findDepatment(@PathVariable String departmentId){  
  
  System.out.println("Find department with ID: " + departmentId);  
  return "someResult";  
  
}  

形如REST风格的地址访问,比如:
/departments/23,其中用(@PathVariable接收rest风格的参数

 

posted @ 2017-08-02 20:24  zhaop  阅读(154)  评论(0编辑  收藏  举报