knife4j 基于Swagger-UI拓展 API文档生产工具

 

相对于  swagger    只需要加个依赖,

<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger2</artifactId>
</dependency>
<--
    <dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-swagger-ui</artifactId>
    </dependency>   
-->     

<dependency>
    <groupId>com.github.xiaoymin</groupId>
    <artifactId>swagger-bootstrap-ui</artifactId>
    <version>1.8.1</version>
</dependency>

最新版 集成  只有一个依赖

<dependency>
    <groupId>com.github.xiaoymin</groupId>
    <artifactId>knife4j-spring-boot-starter</artifactId>
    <!--在引用时请在maven中央仓库搜索最新版本号-->
    <version>2.0.5</version>
</dependency>

 

.浏览器访问 http://localhost:8091/fp/doc.html   ==> 网址/doc.html

举例

1.controller  写法

package cn.yilixun.jt.cfec.fp.controller;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONObject;

import cn.yilixun.fw.common.util.StringUtil;
import cn.yilixun.fw.common.vo.ServiceResultInfo;
import cn.yilixun.jt.cfec.common.service.iface.ApplyRuleDinguserReadInfoService;
import cn.yilixun.jt.cfec.common.service.iface.ApplyRuleInfoService;
import cn.yilixun.jt.cfec.common.vo.ApplyRuleInfo;
import cn.yilixun.jt.cfec.fp.controller.common.FpCommonController;
import cn.yilixun.jt.cfec.fp.vo.ApplyRuleInfoVo;
import cn.yilixun.jt.cfec.fp.vo.RuleDisplayInfoVO;
import cn.yilixun.jt.cfec.fp.vo.common.ResultInfoVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import springfox.documentation.annotations.ApiIgnore;

/**
 * RuleController.
 * 
 * @Title:RuleController.java.
 * @Description ProjectCont roller.java.
 */
@RestController
@RequestMapping("/u/rule")
@Api(tags = "选课规则的相关接口")
public class RuleController extends FpCommonController {
    
    @Autowired
    private ApplyRuleDinguserReadInfoService applyRuleDinguserReadInfoService;
    @Autowired
    private ApplyRuleInfoService applyRuleInfoService;
    
    /**
     * 查看是否已点击规则不再显示.
     */
    @SuppressWarnings("unchecked")
    @RequestMapping(value = "/queryApplyRuleStuReadInfo.action", method = RequestMethod.POST)
    @ApiOperation("查看是否已点击规则不再显示")
    @ApiImplicitParams({@ApiImplicitParam(name = "userId", value = "fp系统用户id", defaultValue = "", required = true),
            @ApiImplicitParam(name = "appUserId", value = "钉钉用户id", defaultValue = "", required = true)})
    public ResultInfoVo<RuleDisplayInfoVO> queryApplyRuleStuReadInfo(@RequestBody @ApiIgnore JSONObject param) {
        String appUserId = param.getString("appUserId");
        if (StringUtil.isEmpty(appUserId)) {
            return ResultInfoVo.getWarningResponse(super.getMsg("common.error.E0001"));
        }
        RuleDisplayInfoVO ruleDisplayInfoVO = new RuleDisplayInfoVO();
        ServiceResultInfo r = applyRuleDinguserReadInfoService.queryApplyRuleDinguserReadInfo(appUserId);
        long count = (long) r.getData();
        if (count > 0) {
            ruleDisplayInfoVO.setRuleDisplayState("0");
        } else {
            ruleDisplayInfoVO.setRuleDisplayState("1");
        }
        return ResultInfoVo.getSuccessResponse(ruleDisplayInfoVO);
    }
    
    /**
     * 显示当前规则.
     */
    @SuppressWarnings("unchecked")
    @RequestMapping(value = "/queryMyRule.action", method = RequestMethod.POST)
    @ApiOperation("显示当前规则")
    @ApiImplicitParams({@ApiImplicitParam(name = "userId", value = "fp系统用户id", defaultValue = "", required = true),
            @ApiImplicitParam(name = "appUserId", value = "钉钉用户id", defaultValue = "", required = true),
            @ApiImplicitParam(name = "gradeYearId", value = "年级id", defaultValue = "", required = true)})
    public ResultInfoVo<ApplyRuleInfoVo> queryMyRule(@RequestBody @ApiIgnore JSONObject param) {
        String gradeYearId = param.getString("gradeYearId");
        if (StringUtil.isEmpty(gradeYearId)) {
            return ResultInfoVo.getWarningResponse(super.getMsg("common.error.E0001"));
        }
        ServiceResultInfo r = applyRuleInfoService.queryApplyRuleInfoFp(gradeYearId);
        ApplyRuleInfo applyRuleInfo = (ApplyRuleInfo) r.getData();
        ApplyRuleInfoVo applyRuleInfoVo = null;
        if (applyRuleInfo != null) {
            applyRuleInfoVo = new ApplyRuleInfoVo();
            applyRuleInfoVo.setNoonCourseMin(applyRuleInfo.getNoonCourseMin());         
            applyRuleInfoVo.setNoonCourseMax(applyRuleInfo.getNoonCourseMax());         
            applyRuleInfoVo.setNightCourseMin(applyRuleInfo.getNightCourseMin());
            applyRuleInfoVo.setNightCourseMax(applyRuleInfo.getNightCourseMax());
            applyRuleInfoVo.setFeatureMin(applyRuleInfo.getFeatureMin());
            applyRuleInfoVo.setFeatureMax(applyRuleInfo.getFeatureMax());
            applyRuleInfoVo.setProTypeMin(applyRuleInfo.getProTypeMin());
            applyRuleInfoVo.setProTypeMax(applyRuleInfo.getProTypeMax());
        }
        return ResultInfoVo.getSuccessResponse(applyRuleInfoVo);
    }
    
    /**
     * 保存规则下次不再提醒.
     */
    @SuppressWarnings("unchecked")
    @RequestMapping(value = "/saveApplyRuleStuReadInfo.action", method = RequestMethod.POST)
    @ApiOperation("保存规则下次不再提醒")
    @ApiImplicitParams({@ApiImplicitParam(name = "userId", value = "fp系统用户id", defaultValue = "", required = true),
            @ApiImplicitParam(name = "appUserId", value = "钉钉用户id", defaultValue = "", required = true)})
    public ResultInfoVo<Map<String, Object>> saveApplyRuleStuReadInfo(@RequestBody @ApiIgnore JSONObject param) {
        String appUserId = param.getString("appUserId");
        if (StringUtil.isEmpty(appUserId)) {
            return ResultInfoVo.getWarningResponse(super.getMsg("common.error.E0001"));
        }
        applyRuleDinguserReadInfoService.saveApplyRuleDinguserReadInfo(appUserId);
        Map<String, Object> map = new HashMap<String, Object>();
        return ResultInfoVo.getSuccessResponse(map);
    }
}

@ApiIgnore声明的不显示 

如果参数为对象,或者list   则使用  @RequestBody 声明

@SuppressWarnings("unchecked")
    @RequestMapping(value = "/saveApplyRuleStuReadInfo.action", method = RequestMethod.POST)
    @ApiOperation("保存规则下次不再提醒")
   
    public ResultInfoVo<Map<String, Object>> saveApplyRuleStuReadInfo(@RequestBody User user) {
        
        return ResultInfoVo.getSuccessResponse(null);
    }

VO实体写法

package cn.yilixun.jt.cfec.fp.vo;

import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;

/**
 * AbilityInfoVo.
 * @Title:AbilityInfoVo.java
 * @Description AbilityInfoVo.java
 */
public class AbilityInfoVo {
    /* 能力编号 */
    @Getter
    @Setter
    @ApiModelProperty(value="能力编号")
    private String abilityNo;
    /* 能力名称 */
    @Getter
    @Setter
    @ApiModelProperty(value="能力名称")
    private String abilityName;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值