swagger从零到有系列

springboot 整合 swagger

国际惯例引入依赖

<!-- 接口swagger -->
		<dependency>
			<groupId>io.springfox</groupId>
			<artifactId>springfox-swagger2</artifactId>
			<version>2.6.1</version>
		</dependency>
		
		<dependency>
			<groupId>io.springfox</groupId>
			<artifactId>springfox-swagger-ui</artifactId>
			<version>2.6.1</version>
		</dependency>

第二步 配置文件

@Configuration
public class SwaggerConfig {

	@Bean
	public Docket createRestApi() {
		return new Docket(DocumentationType.SWAGGER_2)
				.apiInfo(apiInfo())
				.select()
				.apis(RequestHandlerSelectors.basePackage("你的controller包名"))
				.paths(PathSelectors.any())
				.build();
	}
	
	private ApiInfo apiInfo() {
		return new ApiInfoBuilder()
				.title("文档")
				.description("后台网站登录地址")
				.termsOfServiceUrl("www.baidu.html")
				.version("1.0")
				.build();
	}
}

第三步 类

@Api(value="素材管理信息",tags={"操作素材接口"})
@RestController
@RequestMapping("mat")
public class MaterialController {
	
	@Autowired private MaterialService materialService;
	
	/**
	 * 素材列表查询
	 * @param page
	 * @param pageSize
	 * @return
	 */
	@ApiOperation(value="素材列表查询", notes="分页查询当前素材列表信息")
	@ApiImplicitParams({
		@ApiImplicitParam(name = "page", value = "当前页码", required = false,dataType = "Integer",  paramType = "query"),
		@ApiImplicitParam(name = "pageSize", value = "当前页记录数", required = false,dataType = "Integer" , paramType = "query")
	})
	@GetMapping("getMaterialList")
	public Result getMaterialList(Integer page,Integer pageSize){
		return materialService.getMaterialList(page,pageSize);
		
	}
	
	/**
	 * 素材列表数据支持
	 * @return
	 */
	@ApiOperation(value="素材列表数据支持", notes="素材列表信息")
	@GetMapping("getPictureList")
	public Result getPictureList(){
		return materialService.getPictureList();
	}
}


然后就溜了溜了…

2 Likes