栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

swagger入门

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

swagger入门

swagger学习笔记

什么是swagger

swagger是通过注解自动生成json或者yml文件,进而解析成api文档的一个组件,利用swagger-ui生成在线的可以实时跟新的api文档,方便前后端和协同开发.

基本配置

@Configuration
public class SwaggerConfig {

@RestController
@RequestMapping("/swagger")
@Api(tags = {“mycontroller”,“swagger学习控制器”},description = “测试Api文档的描述信息”)
public class HelloController {
@RequestMapping("/entity")
public Myentity entity(){
return new Myentity();
}
// @ApiImplicitParam(name =“m”,value = “参数m的描述”,required = false,paramType = “字符串”,dataType = “名值对”)
@ApiImplicitParams(value = {
@ApiImplicitParam(name =“m”,value = “参数m的描述”,required = false,paramType = “字符串”,dataType = “名值对”),
@ApiImplicitParam(name=“n”,value = “n的描述”,required = true,paramType = “字符串(string)”,dataType = “名值对”)
})
@GetMapping("/test")
public String test(String m, String n){
return “test”;
}


@ApiIgnore
@GetMapping("/get")
public String get(){
return “get”;
}
@PostMapping("/post")
//为方法做描述信息
@ApiOperation(value=“post请求方法,做新增需求”,notes = “学习使用post请求的方法”)
public String post(
@ApiParam(name = “用户名(a)”,value = “用户新增提交的用户名”,required = true) String a,
@ApiParam(name=“密码 “,value = “新增用户的密码”,required = true) String b){
return “post”;
}
@MyAnnotation4Swagger
@RequestMapping(”/req”)
public String map( int m){
return “req”;
}

}

entity


@ApiModel
public class Myentity implements Serializable {
@ApiModelProperty(value = “主键”,name=“主键(id)”,required = false,example = “1”,hidden = false)
private Integer id;
@ApiModelProperty(value = “用户名”,name=“用户名(username)”,required = true,example = “张三”,hidden = false)
private String username;
@ApiModelProperty(value = “密码”,name=“密码(password)”,required = true,example = “123456”,hidden = false)
private String password;

public Myentity() {
}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/724366.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号