swagger入门

swagger入门,第1张

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() {
}

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5719914.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-17
下一篇 2022-12-18

发表评论

登录后才能评论

评论列表(0条)

保存