当前位置:网站首页>0701~放假总结
0701~放假总结
2022-07-24 17:43:00 【生活可真难啊】
今天集成了swagger自动生成模板和注册功能的店铺logo上传,都是以前做过的功能;
swagger自动生成步骤;
1.新建模板类,把swagger配置类的代码放进去;
2.自动生成的路径选好即可;
1.新建模板类,把swagger配置类的代码放进去;
package cn.itsource.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
/**
* @ClassName: Swagger2
* @description: 系统API接口文档配置类
* @author ${author}
* @since ${date}
* @Version 1.1.0.1
*/
@Configuration
@EnableSwagger2
public class Swagger2 {
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
//对外暴露服务的包,以controller的方式暴露,所以就是controller的包.
.apis(RequestHandlerSelectors.basePackage("cn.itsource.controller"))
.paths(PathSelectors.any())
.build();
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("系统服务API")
.description("平台服务接口文档说明")
.contact(new Contact("colin", "", "[email protected]"))
.version("1.0")
.build();
}
}2.自动生成的路径选好即可;
//swagger的输出配置
focList.add(new FileOutConfig("/templates/swagger2.java.vm") {
@Override
public String outputFile(TableInfo tableInfo) {
//合并好的内容输出到哪儿?
return rb.getString("OutputDir")+ "/cn/itsource/config/swagger2.java";
}
});阿里云oss上传步骤;
1.后端代码参考官网,把模板扒下来用;
2.前端记得给name;后端接参数的时候用name的值接即可;
3.后端业务完成后拼接参数,把路径返回给前端展示;
1.后端代码参考官网,把模板扒下来用;
@Override
public JSONResult getFileOss(MultipartFile file) {
//文件上传接口(上传到OSS中的bucket)
// Endpoint:地域节点
String endpoint = "oss-cn-chengdu.aliyuncs.com";
// 阿里云账号AccessKey拥有所有API的访问权限,风险很高。强烈建议您创建并使用RAM用户进行API访问或日常运维,请登录RAM控制台创建RAM用户。
String accessKeyId = "这里填id";
String accessKeySecret = "这里填密钥";
// 填写Bucket名称,例如examplebucket。
String bucketName = "0217blog";
//获取上传文件的后缀
String originalFilename = file.getOriginalFilename();//.jpg.jng
int i = originalFilename.lastIndexOf(".");
String fileType = originalFilename.substring(i);
// 填写Object完整路径,完整路径中不能包含Bucket名称,例如exampledir/exampleobject.txt。
//
String fileName = UUID.randomUUID().toString().replace("-", "") + fileType;
// 创建OSSClient实例。
OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
try {
InputStream inputStream = file.getInputStream();
// 创建PutObject请求。
ossClient.putObject(bucketName, fileName, inputStream);
} catch (OSSException oe) {
System.out.println("Caught an OSSException, which means your request made it to OSS, "
+ "but was rejected with an error response for some reason.");
System.out.println("Error Message:" + oe.getErrorMessage());
System.out.println("Error Code:" + oe.getErrorCode());
System.out.println("Request ID:" + oe.getRequestId());
System.out.println("Host ID:" + oe.getHostId());
} catch (Exception ce) {
System.out.println("上传文件OSS异常:" + ce.getMessage());
return JSONResult.error(ce.getMessage());
} finally {
if (ossClient != null) {
ossClient.shutdown();
}
}
//拼接URL地址返回给前端
//https://blog0217.oss-cn-chengdu.aliyuncs.com/77786f3d6f31445bad462e5464085de8.jpg
String url = "https://" + bucketName + "." + endpoint + "/" + fileName;
return JSONResult.success(url);2.前端记得给name;后端接参数的时候用name的值接即可;
@RequestMapping("/file") public JSONResult fileOss(@RequestParam("fileName") MultipartFile file){ return iFileService.getFileOss(file); }<el-upload class="upload-demo" action="http://localhost:1020/hrm/file/file/file" name="fileName" :on-preview="handlePreview" :on-remove="handleRemove" :on-success="handleSuccess" :file-list="fileList" list-type="picture"> <el-button size="small" type="primary">点击上传</el-button> <div slot="tip" class="el-upload__tip">只能上传jpg/png文件,且不超过500kb</div> </el-upload>这里的name要与后端接口的接收参数保持一致;
3.后端业务完成后拼接参数,把路径返回给前端展示;
//拼接URL地址返回给前端 //https://blog0217.oss-cn-chengdu.aliyuncs.com/77786f3d6f31445bad462e5464085de8.jpg
String url = "https://" + bucketName + "." + endpoint + "/" + fileName;
return JSONResult.success(url);
边栏推荐
- Number theory division block explanation example: 2021 Shaanxi Race C
- C语言自定义类型讲解 — 联合体
- 【网络安全】网站中间件存在的解析漏洞
- Demonstration experiment of scrollbar for adjusting image brightness
- Common questions of testers during interview
- How to remove the top picture of the bubble skin article details of solo blog
- C语言中的字符与字符串库函数的使用以及模拟实现
- awk从入门到入土(19)awk扩展插件,让awk如虎添翼
- 阿里巴巴1688按关键字搜索商品 API 使用展示
- ShardingSphere数据库读写分离
猜你喜欢

OpenCV 图片旋转

面会菜评论分析

Scroll bar adjust brightness and contrast

es(1)

C language custom type explanation - Consortium

Getaverse,走向Web3的远方桥梁

Atcoder beginer 202 e - count descendants (heuristic merge on heavy chain split tree for offline query)

Two dimensional convolution -- use of torch.nn.conv2d

Colleges and universities have introduced 23 Philippine doctors with heavy funds, and the relevant departments have launched an investigation!

Number theory division block explanation example: 2021 Shaanxi Race C
随机推荐
Scept: consistent and strategy based trajectory prediction for planned scenarios
Niuke linked list solution record
Definition and storage of adjacency table and adjacency storage of directed graph and undirected graph
2022 牛客暑期多校 K - Link with Bracket Sequence I(线性dp)
Separation and merging of channels
DF2NET三维模型部署
Pay close attention! List of the latest agenda of 2022 open atom open source Summit
ansible自动化运维详解(五)ansible中变量的设定使用、JINJA2模板的使用以及ansible的加密控制
Number theory division block explanation example: 2021 Shaanxi Race C
The most powerful programmer on the earth is equipped with a "three piece set". Do you know what it is?
微信朋友圈的高性能复杂度分析
仅需一个依赖给Swagger换上新皮肤,既简单又炫酷!
C语言编程训练题目:左旋字符串中的k个字符、小乐乐与欧几里得、打印箭型图案、公务员面试、杨树矩阵
Can Lu Zhengyao hide from the live broadcast room dominated by Luo min?
Two dimensional convolution -- use of torch.nn.conv2d
C language to achieve a static version of the address book
PXE高效批量网络装机
Are the top ten securities companies safe and risky to open accounts?
Six ways for JS to implement inheritance
Use prometheus+grafana to monitor MySQL performance indicators