# restapi_demo **Repository Path**: rang/restapi_demo ## Basic Information - **Project Name**: restapi_demo - **Description**: java接口开发统一模板 - **Primary Language**: Java - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2021-10-17 - **Last Updated**: 2025-10-27 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # restapi_demo #### 介绍 java接口开发统一模板 #### 软件架构 springboot rest api使用版本控制+请求加解密+统一异常处理 #### 安装说明 如idea未安装lombok插件,则需要搜索安装 #### 使用说明 1.使用版本控制@ApiVersion(1) 可在方法上加上@ApiVersion(1)注解,控制接口版本号,1表示v1版本,2表示v2版本 举例如下: ``` //版本更新 @ResponseBody @ApiVersion(1) //接口版本 @RequestMapping(value = "/update", method = RequestMethod.POST) public Result versionUpdate(){ Map resultParams = new HashMap(); resultParams.put("pv", "ios"); resultParams.put("versionName", "v1.0.1"); resultParams.put("versionCode", "20"); resultParams.put("downUrl", "http://www.baidu.com"); resultParams.put("versionDesc", "有新版本更新"); resultParams.put("type", "1"); resultParams.put("gap", "0"); return Result.ok(resultParams); } ``` 2.使用@DecryptRequest注解 方法请求需要解密,不需要解密,则设置为@DecryptRequest(false) 举例如下: ``` @ResponseBody @ApiVersion(1) //接口版本 @RequestMapping(value = "/login", method = RequestMethod.POST) @DecryptRequest //请求解密 @EncryptResponse //响应加密 public Result userLogin(@RequestBody String body){ log.info("解密后的body={}",body); Map resultParams = new HashMap(); resultParams.put("name", "kingboyrang"); resultParams.put("id", "1"); resultParams.put("phone", "13621541236"); return Result.ok(resultParams); } ``` 3.使用@EncryptResponse注解 方法响应返回需要加密,不需要加密,则设置为@EncryptResponse(false) 举例如下: ``` @ResponseBody @ApiVersion(1) //接口版本 @RequestMapping(value = "/login", method = RequestMethod.POST) @DecryptRequest //请求解密 @EncryptResponse //响应加密 public Result userLogin(@RequestBody String body){ log.info("解密后的body={}",body); Map resultParams = new HashMap(); resultParams.put("name", "kingboyrang"); resultParams.put("id", "1"); resultParams.put("phone", "13621541236"); return Result.ok(resultParams); } ``` 4.ExceptionController为统一异常处理类 5.程序使用的是aes加解密方式 6.扩展其它加解密方式 (1)继承Crypto接口,实现其它加解密类 (2)修改RRCryptoConfig类中的rrCrypto方法,返回其它加解密类