1. 引入依赖
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.7.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.7.0</version>
</dependency>
2. swagger配置类
@Configuration
@EnableSwagger2
public class SwangerConfig {
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.forCodeGeneration(true)
.groupName("RUIXUN")
.select()
.apis(RequestHandlerSelectors.basePackage("com.vanrui.controller"))
//过滤生成链接
.paths(PathSelectors.any())
.build()
.apiInfo(apiInfo());
}
/**
* the api info
*
* @return api info
*/
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("Api Swagger Document")
.description("前后端联调Swagger Api 文档(@@App调用类接口, ##后台查询类接口, $$后台CRUD类接口)")
.build();
}
}
3. webmvc配置
@Configuration
public class WebMVCConfig extends WebMvcConfigurationSupport {
@Bean
public AnnotationInterceptor annotationInterceptor(){
return new AnnotationInterceptor();
}
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("swagger-ui.html")
.addResourceLocations("swagger-*")
.addResourceLocations("classpath:/META-INF/resources/");
registry.addResourceHandler("/webjars/**")
.addResourceLocations("classpath:/META-INF/resources/webjars/");
}
}
4. 使用
@RestController
@RequestMapping(value = "project/app")
@Api(value = "项目app版本管理", tags = { "$$项目app版本管理" })
public class RxProjectAppController {
@Autowired
RxProjectAppService rxProjectAppService;
@ApiOperation(value = "添加项目app版本")
@PostMapping(value = "add")
public ResponseDTO add(RxProjectApp rxProjectApp) {
rxProjectAppService.addRxProjectApp(rxProjectApp);
return null;
}
}
@Data
@ApiModel
public class RxProjectApp implements Serializable {
/**
* 系统id
*/
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@ApiParam(value="系统id")
private Integer id;
/**
* 项目id
*/
@ApiParam(value="项目id")
private Long projectId;
/**
* app版本id
*/
@ApiParam(value="app版本id")
private Integer appVersionId;
private static final long serialVersionUID = 1L;
}