jeesite集成swagger2
来源:互联网 发布:淘宝卖家怎么上图片 编辑:程序博客网 时间:2024/05/16 07:12
1、在原有的jeesite工程的pom文件中增加swagger依赖
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.4.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.4.0</version>
</dependency>
2、增加swagger的配置类
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
@Configuration
@EnableWebMvc
@EnableSwagger2
@ComponentScan("com.thinkgem.jeesite.test.web")
public class SwaggerConfig extends WebMvcConfigurationSupport{
@Bean
public Docket petApi() {
return newDocket(DocumentationType.SWAGGER_2)
.groupName("api")
.select()
//.paths(regex("/api/.*"))//拦截的接口路径
.build()
.apiInfo(apiInfo());
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("服务平台 API")
.description("服务")
.termsOfServiceUrl("http://www.xxx.cn/")
.contact(new Contact("xxx","http://www.XXXIII.cn/","xxx@qq.com"))
.version("1.0")
.build();
}
}
@ComponentScan指定要扫描的controller的包。
3、在spring-mvc.xml的拦截其中增加静态资源访问控制。
<!--静态资源映射 -->
<mvc:resourcesmapping="/webjars/**" location="classpath:/META-INF/resources/webjars/"/>
4、编写测试controller
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.stereotype.Controller;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
/**
* 测试Controller
*/
@Controller
@Api(description="测试1controller")
@RequestMapping(value="/test1Controller")
public class Test1Controller {
@RequestMapping(value="/getEq/{a}/{b}", method=RequestMethod.GET)
@ApiOperation(value="GET例子", notes="GET测试例子", response=String.class)
public String getEq(@ApiParam(required=true, value="第一个参数")
@PathVariable Stringa,//这个参数必须有
@ApiParam(required=true, value="第二个参数")
@PathVariable Stringb){//这个参数必须有
System.out.println("a================="+a);
System.out.println("b================="+b);
return b;
}
@RequestMapping(value="/postEq", method=RequestMethod.POST)
@ApiOperation(value="POST例子", notes="POST例子", response=String.class)
public String postEq(@ApiParam(required=true, name="a", value="第一个参数")
@RequestParam(required=true) Stringa,//这个参数必须有
@ApiParam(required=false, name="b", value="第二个参数")
@RequestParam(required=false) Stringb){//这个参数可有可无
System.out.println("a================="+a);
System.out.println("b================="+b);
return b;
}
}
4、启动项目,在浏览器中访问http://localhost:8080/jeesite/swagger-ui.html即可。
具体的controller中的@Api注解信息,参考
https://github.com/wkennedy/swagger4spring-web
http://www.cnblogs.com/softidea/p/6251249.html
- jeesite集成swagger2
- jeesite中集成Swagger2 三步
- Spring Boot 集成Swagger2
- Springboot集成swagger2
- Spring Boot集成Swagger2
- springboot项目集成Swagger2
- SpringBoot集成Swagger2
- SpringMvc 集成swagger2
- springboot集成swagger2
- SpringMvc4集成swagger2
- springboot集成swagger2
- springMVC4集成swagger2
- SpringMVC集成swagger2
- spring boot集成swagger2
- Springboot集成Swagger2
- SpringBoot集成Swagger2
- jeesite集成cas认证
- spring-boot集成Springfox[Swagger2]
- 切换窗口
- SQL 选择结果连接
- 关于GitPush时失败,commitId错误
- HDU 5835 Danganronpa ---规律题
- 砖垛之RecyclerView
- jeesite集成swagger2
- checkstyle auto-fix by python
- LRU缓存介绍与实现 (Java)
- How to create a maven repository for your github project step by step
- Android framwork 之Android makefile编写
- jstl标签详解
- mybatis 详解(九)------ 一级缓存、二级缓存
- [My SQL] SQL聚集函数
- swift之UITableView用法详解