//maven依赖
<!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger2 -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.8.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger-ui -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.8.0</version>
</dependency>
<!--swagger-bootstrap-ui-->
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>swagger-bootstrap-ui</artifactId>
<version>1.9.0</version>
</dependency>
//配置
@Configuration
@EnableSwagger2
@EnableSwaggerBootstrapUI
public class SwaggerConfig {
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.groupName("商户平台API")
.select()
.apis(RequestHandlerSelectors.basePackage("com.baidu.bsm.controller"))//更换com.baidu.bsm.controller为自己的项目controller路径
.paths(PathSelectors.any())
.build();
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("商户平台API") //标题
.description("商户管理平台API文档(内部文档,请勿外传)") //描述
.termsOfServiceUrl("https://www.baidu.com")
.contact(new Contact("XXX有限公司", "https://www.baidu.com", "74532604@qq.cn"))
.version("1.0") //版本
.build();
}
}
//使用
@RestController
@RequestMapping(value = "/api/")
@Api(tags = "违纪管理API", description = "违纪管理API")
public class DisciplineController {
/**
* 新建违纪
*
* @param violation 违纪实体
*/
@PostMapping(value = "v1/discipline_add")
@ApiOperation(value = "新建严重违纪", notes = "violation:违纪实体")
public Response disciplineAdd(@RequestBody Violation violation) {
return disciplineService.disciplineAdd(violation);
}
@Configuration
@ComponentScan
@SpringBootApplication
public class ActivitiApplication {
public static void main(String[] args) {
SpringApplication.run(ActivitiApplication.class, args);
}
}
}