美文网首页
SpringBoot与HTTP请求

SpringBoot与HTTP请求

作者: GambitP_P | 来源:发表于2019-08-14 21:05 被阅读0次
    1. GET(查询,参数在URL后拼接)

    2. DELETE(删除,参数在URL后拼接)

    3. PUT(更新,参数在URL后拼接)

    4. POST(保存,参数放入body中,格式使用application/x-www-form-urlencoded)

    5. Spring Boot相关注解

    //包含在path中提交参数
    @RequestMapping(path = "/{id}", method = RequestMethod.GET)
    public String getStore(@PathVariable String id) {}
    
    //可代替@RequestMapping(method = RequestMethod.GET)
    @GetMapping 
    
    //可代替@RequestMapping(method = RequestMethod.POST)
    @PostMapping
    
    //可代替@RequestMapping(method = RequestMethod.PUT)
    @PutMapping 
    
    // 可代替@RequestMapping(method = RequestMethod.DELETE)
    @DeleteMapping
    ​
    //可以设置默认值,比如分页 
    @RequestParam(value = "name", required = true)
    
    //请求体映射实体类,需要指定http头的content-type为application/json,charset=utf-8
    @RequestBody
    ​
    //请求头,比如鉴权
    @RequestHeader("access_token") String accessToken
    ​
    //使用自动注入获取参数
    HttpServletRequest request
    

    相关文章

      网友评论

          本文标题:SpringBoot与HTTP请求

          本文链接:https://www.haomeiwen.com/subject/yconjctx.html