zoukankan      html  css  js  c++  java
  • SpringBoot注解

    URL中的参数注解

    1、获取url中的数据:@PathVariable 

    URL = localhost:8080/api/{databaseKey}/file

    为了获取URL中的databasekey,可以如下编写代码

    @RestController
    @RequestMapping("/api")
    public class FileController {
        @RequestMapping("/{databaseKey}/file")
        public String getDatabaseKey(@PathVariable String databaseKey) {
            return databaseKey;
        }
    }

    备注:通过@PathVariable注解来获取URL中参数的前提条件是已经提前知道URL的格式是什么样子

    2、获取请求参数的值:@RequetParam

    URL = localhost:8080/api/file?fileKey=M201876146

    为了获取fileKey的值,可以如下编写代码

    @RestController
    @RequestMapping("/api")
    public class FileController {
        @RequestMapping("/file")
        public String getDatabaseKey(@RequestParam("fileKey") String fileKey) {
            return fileKey;
        }
    }

    常用注解

    1、请求映射注解:@RequestMapping

    参数value : 请求映射的地址

    参数method : 将请求映射到一个特定的HTTP方法(GET/PUT/POST/DELETE)

    参数consumesproduces用来缩小请求映射类型的范围,consumes指定处理请求的提交内容;produces指定返回的内容类型,例如

    @RequestMapping(method = RequestMethod.POST, value="/{databaseKey}/files",consumes = MediaType.MULTIPART_FORM_DATA_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)接受表单数据,返回JSON数据

    未完待续。。。

  • 相关阅读:
    c++中关于用stringstream进行的类型转化
    c++中字符串的反转
    搬家
    初次见面,请多关照。
    CCPC2019吉林省赛&&东北地区赛游记
    VS Code下搭建简单的Haskell开发环境
    从零开始的KMP&&AC自动机
    从零开始的LCA(最近公共祖先)
    LuoguP2123 皇后游戏
    LuoguP1080 国王游戏
  • 原文地址:https://www.cnblogs.com/SChenqi/p/10511311.html
Copyright © 2011-2022 走看看