springMVC swagger2
2021-06-29 11:07
标签:handlers out scan cto response ati res ice desc 参考地址:https://www.cnblogs.com/exmyth/p/7183753.html 1. maven 依赖 2. Swagger UI模板 下载地址:https://github.com/swagger-api/swagger-ui swagger-ui-master/dist/index.html 访问配置 3. swagger 配置文件 4. Controller中使用注解添加API文档 5.web.xml配置说明 6. 效果展示 index.html 中修改url: springMVC swagger2 标签:handlers out scan cto response ati res ice desc 原文地址:https://www.cnblogs.com/newlangwen/p/9646206.html@Configuration // 配置注解,自动在本类上下文加载一些环境变量信息
@EnableWebMvc
@EnableSwagger2 // 使swagger2生效
@ComponentScan(basePackages="com.test.controller") //需要扫描的包路径
public class SpringfoxConfig extends WebMvcConfigurationSupport{
@Bean
public Docket petApi() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors
.basePackage("com.test.controller")).build();
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder().title("swagger API").description("")
.termsOfServiceUrl("http://localhost:8080").version("1.0")
.build();
}
}
@Controller
@RequestMapping("/person")
@Api(tags="个人业务")
public class PersonController {
@RequestMapping(value="/getPerson",method= RequestMethod.GET)
@ApiOperation(httpMethod = "GET", value = "个人信息", produces = MediaType.APPLICATION_JSON_VALUE)
public @ResponseBody Person getPersons() {
Person person = new Person();
person.setFirstName("fname");
person.setLastName("lname");
person.setAge(37);
person.setDeptName("dept");
return person;
}
}
文章标题:springMVC swagger2
文章链接:http://soscw.com/index.php/essay/99349.html