一、添加POM依赖
<!-- swagger2 dependency -->
<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>
二、配置
@Configuration
@EnableSwagger2
@ConditionalOnExpression("${swagger.ui:false}")
public class Swagger2 {
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).select()
.apis(RequestHandlerSelectors.basePackage("com.aspire.parsehlrandmo.controller"))
.paths(PathSelectors.any()).build();
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder().title("标题").description("描述").contact(new Contact("Sam", "", ""))
.version("1.0").build();
}
}
三、接口中使用
@RestController
@RequestMapping("/namespace")
@Api(value = "解析数据", tags = {"解析数据接口"})
@Slf4j
public class ParseController {
@Autowired
private ParseExcelToSql parseExcelToSql;
@Value("${com.test.path}")
private String path;
/**
* 导出信息.
*
* @return 导出信息
*/
@ApiOperation(value = "解析excel", notes = "解析excel并生成脚本")
@RequestMapping(value = "/parseExcel", method = RequestMethod.POST)
public String parseExcel(@RequestBody String excelPath) {
log.info("传入路径为" + excelPath);
parseExcelToSql.parseExcel(path);
return "success";
}
}