In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/03 Report--
1. Concept
Swagger2-Service interface document, used for front-end and back-end contact, improve communication between projects, more efficient completion of joint adjustment between projects.
2. Integration
2.1.Import swagger through pom file
Swagger-springmvc
Swagger-springmvc
2.2.Building swagger module and writing module class
@ Configuration
@ EnableWebMvc
@ EnableSwagger
@ ComponentScan (basePackages= {"com.sz.xx"})
Public class ApiSwaggerConfig extends WebMvcConfigurerAdapter {
Private SpringSwaggerConfig springSwaggerConfig
@ Autowired
Public void setSpringSwaggerConfig (SpringSwaggerConfig springSwaggerConfig)
{
This.springSwaggerConfig = springSwaggerConfig
}
@ Bean
Public SwaggerSpringMvcPlugin customImplementation ()
{
Return new SwaggerSpringMvcPlugin (this.springSwaggerConfig) .apiInfo (apiInfo ()) .origindePatterns (new String [] {"/ xx/.*?"})
.apiVersion ("0.0.1")
.swagger Group ("api")
}
Private ApiInfo apiInfo () {
ApiInfo apiInfo = new ApiInfo ("XX API Interface document", "API-DOC", "test@163.com", "My License", "My Apps API License URL")
Return apiInfo
}
Public void configureDefaultServletHandling (DefaultServletHandlerConfigurer configurer)
{
Configurer.enable ()
}
Class GtPaths extends SwaggerPathProvider {
GtPaths () {
}
Protected String applicationPath () {
Return "/ restapi"
}
Protected String getDocumentationPath ()
{
Return "/ restapi"
}
}
}
}
3. Use swagger in the code
3.1 、 UserContoller
Api (value= "userApi", description= "user Management Interface", position=1)
@ Controller
@ ApiService
Public class UserContoller {
@ ApiOperation (notes= "new user interface", value= "new user (developer responsible person: xx)")
@ ApiServiceOperation ("New user Interface")
@ RequestMapping (value= {"/ xx/user/add"}, method= {RequestMethod.POST})
@ ResponseBody
Public Response createSoftsimBinding (@ RequestBody SoftsimBindingCreateReq req)
{
}
4. Import swagger-related ui into the project, and you can create a static folder to store swagger ui files.
5. Access via address http://localhost:8020/swagger/index.html
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.