当前位置:网站首页>0701~ holiday summary
0701~ holiday summary
2022-07-24 17:48:00 【Life is so hard】
Integrated today swagger Stores that automatically generate templates and register functions logo Upload , They are all functions that have been done before ;
swagger Automatically generate steps ;
1. Create a new template class , hold swagger Put the code of the configuration class ;
2. The automatically generated path can be selected ;
1. Create a new template class , hold swagger Put the code of the configuration class ;
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: System API Interface document configuration class
* @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()
// Package of external exposure Services , With controller The way to expose , So is controller My bag .
.apis(RequestHandlerSelectors.basePackage("cn.itsource.controller"))
.paths(PathSelectors.any())
.build();
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title(" system service API")
.description(" Platform service interface document description ")
.contact(new Contact("colin", "", "[email protected]"))
.version("1.0")
.build();
}
}2. The automatically generated path can be selected ;
//swagger Output configuration for
focList.add(new FileOutConfig("/templates/swagger2.java.vm") {
@Override
public String outputFile(TableInfo tableInfo) {
// Where to output the merged content ?
return rb.getString("OutputDir")+ "/cn/itsource/config/swagger2.java";
}
});Alibaba cloud oss Upload steps ;
1. Refer to the official website for the back-end code , Remove the formwork and use ;
2. Remember to give the front end name; When connecting parameters at the back end, use name The value of ;
3. Splicing parameters after the completion of back-end business , Return the path to the front-end display ;
1. Refer to the official website for the back-end code , Remove the formwork and use ;
@Override
public JSONResult getFileOss(MultipartFile file) {
// File upload interface ( Upload to OSS Medium bucket)
// Endpoint: Regional nodes
String endpoint = "oss-cn-chengdu.aliyuncs.com";
// Alicloud account AccessKey Have all the API Access rights of , The risk is high . It is highly recommended that you create and use it RAM The user carries out API Visit or daily operations , Please log in RAM Console creation RAM user .
String accessKeyId = " Fill in here id";
String accessKeySecret = " Fill in the key here ";
// Fill in Bucket name , for example examplebucket.
String bucketName = "0217blog";
// Get the suffix of the uploaded file
String originalFilename = file.getOriginalFilename();//.jpg.jng
int i = originalFilename.lastIndexOf(".");
String fileType = originalFilename.substring(i);
// Fill in Object The full path , The full path cannot contain Bucket name , for example exampledir/exampleobject.txt.
//
String fileName = UUID.randomUUID().toString().replace("-", "") + fileType;
// establish OSSClient example .
OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
try {
InputStream inputStream = file.getInputStream();
// establish PutObject request .
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(" Upload files OSS abnormal :" + ce.getMessage());
return JSONResult.error(ce.getMessage());
} finally {
if (ossClient != null) {
ossClient.shutdown();
}
}
// Splicing URL The address is returned to the front end
//https://blog0217.oss-cn-chengdu.aliyuncs.com/77786f3d6f31445bad462e5464085de8.jpg
String url = "https://" + bucketName + "." + endpoint + "/" + fileName;
return JSONResult.success(url);2. Remember to give the front end name; When connecting parameters at the back end, use name The value of ;
@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"> Click upload </el-button> <div slot="tip" class="el-upload__tip"> Can only upload jpg/png file , And no more than 500kb</div> </el-upload>there name Keep consistent with the receiving parameters of the back-end interface ;
3. Splicing parameters after the completion of back-end business , Return the path to the front-end display ;
// Splicing URL The address is returned to the front end //https://blog0217.oss-cn-chengdu.aliyuncs.com/77786f3d6f31445bad462e5464085de8.jpg
String url = "https://" + bucketName + "." + endpoint + "/" + fileName;
return JSONResult.success(url);
边栏推荐
- Interview assault 66: what is the difference between request forwarding and request redirection?
- C语言中的字符与字符串库函数的使用以及模拟实现
- Scept: consistent and strategy based trajectory prediction for planned scenarios
- C语言自定义类型 — 枚举
- 0621~ES&Lucene
- SSM framework learning
- C language custom types - Enumeration
- Brats18 - Multimodal MR image brain tumor segmentation challenge continued
- C language programming training topics: K characters in left-handed string, little Lele and Euclidean, printing arrow pattern, civil servant interview, poplar matrix
- Can CSC open an account for domestic futures? Is it safe?
猜你喜欢

Internship report 1 - face 3D reconstruction method

Opencv picture rotation

Getaverse, a distant bridge to Web3

二维卷积——torch.nn.conv2d的使用

DF2NET三维模型部署
![[leetcode] 30. Concatenate substrings of all words](/img/21/3965532a31553cfe6edf64ca5de3f4.png)
[leetcode] 30. Concatenate substrings of all words

使用Prometheus+Grafana监控MySQL性能指标

Scept: consistent and strategy based trajectory prediction for planned scenarios

快速完成intelij idea的单元测试JUnit4设置

C语言中的字符与字符串库函数的使用以及模拟实现
随机推荐
A problem of MySQL database
Can Lu Zhengyao hide from the live broadcast room dominated by Luo min?
Awk from entry to earth (17) awk multiline writing
二维卷积——torch.nn.conv2d的使用
[waiting for insurance] what does waiting for insurance rectification mean? What are the rectification contents?
After separation, the impression notes are still difficult to live, but there are many coquettish operations
mac数据库管理软件Navicat Premium Essentials Mac
Gan Development Series II (pggan, Singan)
干货|值得收藏的三款子域名收集工具
The use and Simulation of character and string library functions in C language
0629~SaaS平台设计~全局异常处理
阿里巴巴1688按关键字搜索商品 API 使用展示
int8 & int8,你栽过这样的跟头吗?
Getaverse, a distant bridge to Web3
Extension of ES6 function
Analog electricity - what is the resistance?
awk从入门到入土(17)awk多行写法
Use yarn
700. Search DFS method in binary search tree
High performance complexity analysis of wechat circle of friends