码迷,mamicode.com
首页 > 其他好文 > 详细

swagger - ssm

时间:2019-05-14 09:41:07      阅读:140      评论:0      收藏:0      [点我收藏+]

标签:tps   uil   文件   docke   bean   stc   5.0   nta   esc   

swagger - ssm

 

1、porm.xml

<dependency>
	<groupId>io.springfox</groupId>
	<artifactId>springfox-swagger2</artifactId>
	<version>2.5.0</version>
</dependency>
<dependency>
	<groupId>io.springfox</groupId>
	<artifactId>springfox-swagger-ui</artifactId>
	<version>2.5.0</version>
	</dependency>
<dependency>
	<groupId>com.mangofactory</groupId>
	<artifactId>swagger-springmvc</artifactId>
	<version>0.9.5</version>
</dependency>

 

2、swagger 配置

技术图片

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;

import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;


@Configuration
@EnableSwagger2
@EnableWebMvc
public class Swagger2 {

    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.common.base.modules"))
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder().title("Swagger").description("show").termsOfServiceUrl("no terms of service")
                .version("2.0")
                .build();
    }

}

  

 3、在spring-mvc.xml的配置文件里面配置扫描到上面那个 swagger 2 文件

<context:component-scan base-package="com.common.base.swagger" />

  

 4、controller 配置例 - 配置 Api 

@RestController
@RequestMapping("/items")
public class ItemController {
	
	@Autowired
	private ItemService itemService;
	

	@RequestMapping(value="/queryItems", method=RequestMethod.GET)
	@ApiOperation(value="Items",notes="Items")
        public JSONObject queryItems(HttpServletRequest request) {
                 return itemService.queryItem((CommonUtil.request2Json(request)));
        }
}

  

完成

技术图片

 

swagger - ssm

标签:tps   uil   文件   docke   bean   stc   5.0   nta   esc   

原文地址:https://www.cnblogs.com/Jomini/p/10860318.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!