在springboot项目中 集成swagger :
1.添加swagger依赖,如下
<!-- swagger -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.8.0</version>
</dependency>
<!-- swagger-ui -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.8.0</version>
</dependency>
2.配置 SwaggerConfig 如下:
@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket swaggerSpringMvcPlugin() {
return new Docket(DocumentationType.SWAGGER_2).select().apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class)).build();
}
}
3.写controller:
@Api(description = "用户接口")
@RestController
public class DemoController {
private static final Logger logger = LoggerFactory.getLogger(DemoController.class);
@ApiOperation(value = "新增用户" , notes="新增注册")
@RequestMapping(value="/createUser",method=RequestMethod.POST,consumes= MediaType.APPLICATION_JSON_VALUE)
public ResObject createUser(@RequestBody User user){
logger.info("用户信息:"+user.toString());
return new ResObject(HttpStatus.OK.value(), "新增成功.");
}
}
另外,还有在线的api接口文档管理平台 http://www.sosoapi.com/auth/home/home.htm