1.逻辑删除
a.要执行删除操作的数据表中添加is_deleted字段,初始值设为0 b.对应实体类要删除的字段加上@TableLogic注解
2.swagger配置
a.对应pom.xml添加如下依赖:
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
</dependency>
b.在service的工具类下创建swagger配置类
package com.zlm.yygh.common.config;
import com.google.common.base.Predicates;
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.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;
/**
* Swagger2配置信息
*/
@Configuration
@EnableSwagger2
public class Swagger2Config {
@Bean
public Docket webApiConfig(){
return new Docket(DocumentationType.SWAGGER_2)
.groupName("webApi")
.apiInfo(webApiInfo())
.select()
//只显示api路径下的页面
.paths(Predicates.and(PathSelectors.regex("/api/.*")))
.build();
}
@Bean
public Docket adminApiConfig(){
return new Docket(DocumentationType.SWAGGER_2)
.groupName("adminApi")
.apiInfo(adminApiInfo())
.select()
//只显示admin路径下的页面
.paths(Predicates.and(PathSelectors.regex("/admin/.*")))
.build();
}
private ApiInfo webApiInfo(){
return new ApiInfoBuilder()
.title("网站-API文档")
.description("本文档描述了网站微服务接口定义")
.version("1.0")
.contact(new Contact("atguigu", "http://atguigu.com", "493211102@qq.com"))
.build();
}
private ApiInfo adminApiInfo(){
return new ApiInfoBuilder()
.title("后台管理系统-API文档")
.description("本文档描述了后台管理系统微服务接口定义")
.version("1.0")
.contact(new Contact("zlm", "http://zlm.com", "1328549293@qq.com"))
.build();
}
}
其中,@Configuration为配置类创建需添加的注解,@EnableSwagger2为开启swagger的注解,注意swagger一定要选择能和springboot版本兼容的版本。 属性注释:groupName:分组名可自己随便定义,apiInfo:相关api信息
c.对应启动类上上添加```
@ComponentScan(basePackages = "com.zlm")
注解basePackages的取值对应你pom.xml中定义工具类的groupId的值,配置在不同的子项目中的话则对应于父级项目中的pom中的工具类的groupId的值。例如项目结构如下:
如果是在子项目common下的子项目service_util中定义的swagger配置类,若service下的子项目service_hosp的服务要用swagger配置类,则需要在其父级项目的service的pom中定义service_util依赖,配置如下:
<dependency>
<groupId>com.zlm</groupId>
<artifactId>service_util</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
d.swagger访问:http://localhost:8201/swagger-ui.html
常用注解:
@Api(tags="医院管理设置")
用于定义controller功能
@ApiOperation(value = "获取所有医院信息")
用于定义controller下对应方法的功能注解,配置好后点击对应接口下的try it out 就可以看到返回值啦