Swagger2基础配置

1.实体类
 @Data 相当于生成了get set
 @AllArgsConstructor 有参构造函数
 @NoArgsConstructor
 @Column(name = "id") 字段名
 @Table(name = "user")
 @Id 主键
 @KeySql="True" 自动增长,可以不加
 Lombok插件
 TKMapper插件:
   MyBatis的第三方插件
2.DAO层
    定义操作数据库的接口
    @Repository 表示DAO层
    继承Mapper
3.Service层
    定义业务逻辑
    @Service 表示业务层
    @Autowired 将dao层注入业务层
      private UserDao userDao;
4.Controller层
    @RestController 表示控制层
    @Resource 调用业务层
      private UserService userService;
    @RequestMapping("/login")
5.启动类
    @MapperScan("com.example.maventwo.dao")扫描dao
6.Swagger
    用于生成在线文档,测试接口
 <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.18.28</version>
        </dependency>
        <dependency>
            <groupId>tk.mybatis</groupId>
            <artifactId>mapper-spring-boot-starter</artifactId>
            <version>4.2.3</version>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>2.9.2</version>
        </dependency>

        <dependency>
            <groupId>com.github.xiaoymin</groupId>
            <artifactId>swagger-bootstrap-ui</artifactId>
            <version>1.9.6</version>
        </dependency>

        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>2.9.2</version>
        </dependency>
        <dependency>
            <groupId>com.github.pagehelper</groupId>
            <artifactId>pagehelper-spring-boot-starter</artifactId>
            <version>1.4.7</version>
        </dependency>
package com.example.maventwo.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;

@EnableSwagger2
@Configuration
public class SwaggerConfig {
    @Bean
    public Docket getDocket(){
        //创建封面
        ApiInfoBuilder apiInfoBuilder = new ApiInfoBuilder();
        apiInfoBuilder
                .title("《后台管理系统》后端接口说明文档")
                .description("后端接口规范")
                .version("v1.0.0")
                .contact(new Contact("lee","www.xiaoming.com","22@qq.com"));
        ApiInfo apiInfo = apiInfoBuilder.build();
        Docket docket = new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo) //生成指定文档封面
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.example.maventwo.controller"))
                .paths(PathSelectors.any())
                .build();
        return docket;
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值