28 Star 97 Fork 44

江南久无雪/jfinal-swagger

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

JFinal-Swagger

上周开始接触JFinal框架,第一感觉就是提高了开发速度。之前使用Spring的时候,方便API文档生成,便集成了Swagger 在研究一段时间后,决定将Swagger集成到JFinal中,由于时间仓促,当前第一版本提供基础功能

JFinal-Swagger 使用说明

  • mvn clean
  • mvn install

参考Demo

1. 添加依赖

    <dependency>
        <groupId>com.feizhou</groupId>
        <artifactId>jfinal-swagger</artifactId>
        <version>1.0-SNAPSHOT</version>
    </dependency>

2. 下载 swagger-ui-master 将 dist 中文件加入到项目中

可配置成类似如下路径:
    webapp
        static
            swagger
                favicon-16x16.png
                ...
                swagger-ui.js.map
    WEB-INF
        views
            swagger
                index.html

3. 增加Swagger路由控制

    // 可以用此方式增加全局参数 如token
    SwaggerGlobalPara.addPara(new SwaggerPath.Parameter(
            "x-access-token", "header", "令牌", false, "string", "", ""
    ));
        
    以第二步的形式配置的目录结构,可直接使用如下路由配置
    routes.add(new SwaggerRoutes());
    
    也可自行配置路由信息
    
    public class SwaggerRoutes extends Routes {
    
        @Override
        public void config() {
            setBaseViewPath("/WEB-INF/views");
            add("/swagger", SwaggerController.class);
        }
    
    }

4. 添加注解

    提供四种注解:
    
    @Api(tag = "index", description = "测试输出")
    
    @ApiOperation(url = "/test", tag = "index", httpMethod = "get", description = "测试json")
    
    @Param(name = "id", description = "编号", required = true, dataType = "Long")
    
    @Params
    

5. 配置扫描包信息

    config.properties增加:swagger.base_package
    如:
    swagger.base_package=com.feizhou.swagger.test

6. 增加文件参数支持

    增加 consumes = "multipart/form-data"
    @ApiOperation(url = "/test2", tag = "index", httpMethod = "post", description = "测试json", consumes = "multipart/form-data")
    
    设置 dataType = "file"
    @Param(name = "file", description = "文件", required = true, dataType = "file")

注解使用示例:


@Api(tag = "index", description = "测试输出")
public class IndexController extends Controller {

    public void index() {
        setAttr("aaa", "aaaaaa");
        this.render("index.html");
    }

    @ApiOperation(url = "/test", tag = "index", httpMethod = "get", description = "测试json")
    @Params({
            @Param(name = "id", description = "编号", required = true, dataType = "Long"),
            @Param(name = "name", description = "姓名", required = true, dataType = "String")
    })
    public void test() {
        List<String> list = Arrays.asList("123","456");
        this.renderJson(list);
    }
}
    
MIT License Copyright (c) 2020 江南久无雪 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

jfinal 集成 Swagger 展开 收起
Java
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/leeckent/jfinal-swagger.git
git@gitee.com:leeckent/jfinal-swagger.git
leeckent
jfinal-swagger
jfinal-swagger
master

搜索帮助