本人试验过程 没有遇到什么障碍,非常简单,好用,值得玩耍一下下。

swagger 超简单入门教程 使用(真实自测) - xmind果果 - CSDN博客--这篇文章非常好,收集了很多文章
https://blog.csdn.net/mengxiangxingdong/article/details/82743687

swagger常用注解说明 - 简书
https://www.jianshu.com/p/12f4394462d5

SpringBoot 使用Swagger2打造在线接口文档(附汉化教程) - 简书
https://www.jianshu.com/p/7e543f0f0bd8

全局参数_w3cschool
https://www.w3cschool.cn/swaggerbootstrapui/swaggerbootstrapui-i8nc32i7.html

Swagger常用注解使用详解
http://c.biancheng.net/view/5533.html

//==============

pom.xml 中加入

<swagger.version>2.7.0</swagger.version>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>${swagger.version}</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>${swagger.version}</version>
</dependency>

/**
配置文件
 */

packagecom.eos.wool.config;importio.swagger.annotations.ApiOperation;importorg.springframework.context.annotation.Bean;importorg.springframework.context.annotation.Configuration;importspringfox.documentation.builders.ApiInfoBuilder;importspringfox.documentation.builders.PathSelectors;importspringfox.documentation.builders.RequestHandlerSelectors;importspringfox.documentation.service.ApiInfo;importspringfox.documentation.service.ApiKey;importspringfox.documentation.spi.DocumentationType;importspringfox.documentation.spring.web.plugins.Docket;importspringfox.documentation.swagger2.annotations.EnableSwagger2;importjava.util.List;import staticcom.google.common.collect.Lists.newArrayList;

@Configuration
@EnableSwagger2
public classSwaggerConfig {
@Bean
publicDocket createRestApi() {return newDocket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
//加了ApiOperation注解的类,才生成接口文档 .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))//包下的类,才生成接口文档 .apis(RequestHandlerSelectors.basePackage("com.eos.wool.Controller"))
.paths(PathSelectors.any())
.build()
.securitySchemes(security());
}
privateApiInfo apiInfo() {return newApiInfoBuilder()
.title(
"eos简易工具")
.description(
"-api文档")
.termsOfServiceUrl(
" ")
.version(
"0.0.2")
.build();
}
private List<ApiKey>security() {returnnewArrayList(new ApiKey("token", "token", "header")
);
}

}
写个Controller ,标注好,打包,运行,打开地址 就可以看到了。什么地址忘记了,
/****/
packagecom.eos.wool.Controller;
importcom.eos.wool.service.EosService;importio.bigbearbro.eos4j.Eos4j;importio.bigbearbro.eos4j.api.result.GetAccountResults;importio.bigbearbro.eos4j.api.result.PushTransactionResults;importio.bigbearbro.eos4j.crypto.EccTool;importio.bigbearbro.eos4j.entity.EosAccount;importio.swagger.annotations.Api;importio.swagger.annotations.ApiImplicitParam;importio.swagger.annotations.ApiImplicitParams;importio.swagger.annotations.ApiOperation;importorg.apache.commons.lang.RandomStringUtils;importorg.springframework.beans.factory.annotation.Autowired;importorg.springframework.beans.factory.annotation.Value;import org.springframework.web.bind.annotation.*;importjavax.annotation.Resource;importjava.io.IOException;importjava.text.SimpleDateFormat;import java.util.*;/***@authorrogge
*
* 2018年8月1日 上午9:54:57
*/@RestController
@RequestMapping(
"eos")
@Api(value
= "相关业务的接口",tags="批量接口")public classeosControl {

@Resource
privateEosService eosService;
@Value(
"${eos.mainAccount.name}")privateString mainAccountname;
@Value(
"${eos.mainAccount.pk}")privateString mainAccountPk;
@Value(
"${eos.baseurl}")privateString baseurl;public static List<String> inviteCodelist = new ArrayList<String>();//public static Set<String> idlist = new HashSet<String>(); public static Map<String, String> VidKeyMmap = new HashMap<String, String>();private SimpleDateFormat dFmt= new SimpleDateFormat("yyyy年MM月dd日 HH时mm分ss秒");

@ResponseBody
@RequestMapping(value
="invite/{key}",method =RequestMethod.POST)
@ApiOperation(
"获得邀请码")public String getinviteCode(@PathVariable("key") String mykey) {
String vid
="",key="",pk="";if (mykey.equals("1234567")) {
vid
= RandomStringUtils.randomAlphanumeric(10);if(inviteCodelist.contains(vid)){
vid
="";
}
elseinviteCodelist.add(vid);
}
returnvid;
}

@ResponseBody
@RequestMapping(value
="initVid",method =RequestMethod.POST)
@ApiOperation(value
="获得授权码和公钥",notes="获得授权码和公钥")
@ApiImplicitParams({
@ApiImplicitParam(name
= "inviteCode", value = "邀请码", required = true, dataType = "String", paramType = "query")})public Object getLastTrack(@RequestParam(value = "inviteCode", required = true) String inviteCode) {
String vid
="",key="",pk="";//System.out.println(mykey); if(inviteCodelist.contains(inviteCode.trim())) {//System.out.println(mykey+"12345"); vid= RandomStringUtils.randomAlphanumeric(15);
pk
= EccTool.privateKeyFromSeed("!@#$%^&*(lajdlkjaksjdlkjaskldM<>?87126162kajsdjlaksd kajdlkaslkd heiuheijpe f[a- si0ausd9asd ahsdvcyasdcasdc ajhsdg8ca" + RandomStringUtils.randomAlphanumeric(13)+ "we asds JHDKAHDKKASDKJALSKDKA ooidjajsdua09sid0asdo[paksdajsdlklasdmlk FJKLIKNLK;B/;LP[P'NC;PO'; OOPO;L0[" + RandomStringUtils.randomAlphanumeric(40)+ "XP'C'[FG[" + RandomStringUtils.randomAlphanumeric(56)+ "19218728909107328972309289832098012");
key
=EccTool.privateToPublic2(pk);
VidKeyMmap.put(vid,pk);
inviteCodelist.remove(inviteCode.trim());
//清除 可以设定为3天内有效 Map<String, String> map = new HashMap<String, String>();
map.put(
"授权码",vid);
map.put(
"授权Active到此公钥",key);returnmap;
}
else{return inviteCode+"邀请码无效";
}

}


@ResponseBody
@ApiOperation(value
="批量给账号买内存",
notes
="addFlag为true时直接增量购买buyRAMBytes的量,为false时是内存可使用值补足到buyRAMBytes的量")
@ApiImplicitParams({
@ApiImplicitParam(name
= "vid", value = "授权码", required = true, dataType = "String", paramType = "query"),
@ApiImplicitParam(name
= "accountName", value = "已经绑定的用户名", required = true, dataType = "String", paramType = "query"),
@ApiImplicitParam(name
= "buyRAMBytes", value = "增量或补足的量 (byte)", required = true, dataType = "Integer", paramType = "query"),
@ApiImplicitParam(name
= "addFlag", value = "增量标志", required = true, dataType = "boolean", paramType = "query"),
@ApiImplicitParam(name
= "accountList", value = "账号列表,中间用英文逗号隔开", required = true, dataType = "String", paramType = "query")
})
@RequestMapping(value
= "/buyRAMBytes", method =RequestMethod.POST)public Object batchBuyRAMBytes(@RequestParam(value = "vid", required = true) String vid,
@RequestParam(value
= "accountName", required = true) String accountName,
@RequestParam(value
= "buyRAMBytes", required = true) Integer buyRAMBytes,
@RequestParam(value
= "addFlag", required = true) booleanaddFlag,
@RequestParam(value
= "accountList", required = true) String accountList) throwsIOException{
List
<String> list = new ArrayList<String>();
String PrivateKEY
="";
accountName
=accountName.trim();
System.out.println(vid
+" "+accountName+" "+buyRAMBytes+" "+accountList);if (!VidKeyMmap.keySet().contains(vid.trim())) {
list.add(
"此授权码不存在");returnlist;
}
else{
PrivateKEY
=VidKeyMmap.get(vid);
}
String[] eosAccounts
=accountList.split(",");//购买字节 Long buyRam = 400l;
Eos4j eos4j
= newEos4j(baseurl);int i = 0;int bucong=0;for(String eosAccount : eosAccounts) {if(eosAccount.trim().isEmpty()) {continue;
}
i
++;if (addFlag == true) {
GetAccountResults info
=eos4j.getAccount(eosAccount);int ramshenyu= (int) (info.getRamQuota()-info.getRamUsage());if (ramshenyu >=buyRAMBytes.intValue()) {//System.out.println("超出了"); list.add("成功 "+i+":"+eosAccount+":超值不用买");continue;
}
bucong
=buyRAMBytes.intValue()-ramshenyu+5;
}
else{
bucong
=buyRAMBytes.intValue()+5;
}
buyRam
=(long)bucong;

PushTransactionResults Results3
= null;try{
Results3
=eos4j.buyrambytes(PrivateKEY, accountName, eosAccount, buyRam);if (Results3 != null && Results3.getTransactionId() != "") {
list.add(
"成功 "+i+":"+eosAccount+":购买了"+bucong);
System.out.println(
"表 买内存成功,账号:" + eosAccount + "\t" + i+ "\t"+bucong);
}
}
catch(Exception e) {
e.printStackTrace();
list.add(
"失败 "+i+":"+eosAccount);
}
}
System.out.println(
"执行完毕");
list.add(
"执行完成!");returnlist;
}

}

2022年11月13日  又想起来了,看了蛮久不知道怎么打开,运行日志看不出来,看到这个静态文件 就想起来了。

http://localhost:8887/swagger-ui.html



标签: none

添加新评论