当前位置: 首页 > news >正文

做网站的经历感想百度导航怎么下载

做网站的经历感想,百度导航怎么下载,广西省住房和城乡建设厅官网,做婚恋网站的思路项目场景: springboot项目中同时使用接口文档swagger和knife4j 问题描述 在实体类中设置了字段必填的属性,在访问接口文档时出现异常 实体类关键代码片段 /*** 部门表 sys_dept*/ public class SysDept extends BaseEntity {private static final lo…

项目场景:

springboot项目中同时使用接口文档swagger和knife4j


问题描述

在实体类中设置了字段必填的属性,在访问接口文档时出现异常

实体类关键代码片段

/*** 部门表 sys_dept*/
public class SysDept extends BaseEntity
{private static final long serialVersionUID = 1L;/** 部门ID */private Long deptId;/** 部门名称 */private String deptName;/** 显示顺序 */private Integer orderNum;@NotBlank(message = "部门名称不能为空")@Size(min = 0, max = 30, message = "部门名称长度不能超过30个字符")public String getDeptName(){return deptName;}public void setDeptName(String deptName){this.deptName = deptName;}@NotNull(message = "显示顺序不能为空")public Integer getOrderNum(){return orderNum;}public void setOrderNum(Integer orderNum){this.orderNum = orderNum;}
}

异常描述:

(1)没有加入knife4j配置,仅使用swagger配置

        <dependency><groupId>io.springfox</groupId><artifactId>springfox-swagger2</artifactId><version>3.0.0</version></dependency>
package com.pie.common.swagger.config;@Configuration
@EnableSwagger2
@EnableAutoConfiguration
@ConditionalOnProperty(name = "swagger.enabled", matchIfMissing = true)
public class SwaggerAutoConfiguration
{/*** 默认的排除路径,排除Spring Boot默认的错误处理路径和端点*/private static final List<String> DEFAULT_EXCLUDE_PATH = Arrays.asList("/error", "/actuator/**");private static final String BASE_PATH = "/**";@Bean@ConditionalOnMissingBeanpublic SwaggerProperties swaggerProperties(){return new SwaggerProperties();}@Beanpublic Docket api(SwaggerProperties swaggerProperties){// base-path处理if (swaggerProperties.getBasePath().isEmpty()){swaggerProperties.getBasePath().add(BASE_PATH);}// noinspection uncheckedList<Predicate<String>> basePath = new ArrayList<Predicate<String>>();swaggerProperties.getBasePath().forEach(path -> basePath.add(PathSelectors.ant(path)));// exclude-path处理if (swaggerProperties.getExcludePath().isEmpty()){swaggerProperties.getExcludePath().addAll(DEFAULT_EXCLUDE_PATH);}List<Predicate<String>> excludePath = new ArrayList<>();swaggerProperties.getExcludePath().forEach(path -> excludePath.add(PathSelectors.ant(path)));ApiSelectorBuilder builder = new Docket(DocumentationType.SWAGGER_2).host(swaggerProperties.getHost()).apiInfo(apiInfo(swaggerProperties)).select().apis(RequestHandlerSelectors.basePackage(swaggerProperties.getBasePackage()));swaggerProperties.getBasePath().forEach(p -> builder.paths(PathSelectors.ant(p)));swaggerProperties.getExcludePath().forEach(p -> builder.paths(PathSelectors.ant(p).negate()));return builder.build().securitySchemes(securitySchemes()).securityContexts(securityContexts()).pathMapping("/");}/*** 安全模式,这里指定token通过Authorization头请求头传递*/private List<SecurityScheme> securitySchemes(){List<SecurityScheme> apiKeyList = new ArrayList<SecurityScheme>();apiKeyList.add(new ApiKey("Authorization", "Authorization", "header"));return apiKeyList;}/*** 安全上下文*/private List<SecurityContext> securityContexts(){List<SecurityContext> securityContexts = new ArrayList<>();securityContexts.add(SecurityContext.builder().securityReferences(defaultAuth()).operationSelector(o -> o.requestMappingPattern().matches("/.*")).build());return securityContexts;}/*** 默认的全局鉴权策略** @return*/private List<SecurityReference> defaultAuth(){AuthorizationScope authorizationScope = new AuthorizationScope("global", "accessEverything");AuthorizationScope[] authorizationScopes = new AuthorizationScope[1];authorizationScopes[0] = authorizationScope;List<SecurityReference> securityReferences = new ArrayList<>();securityReferences.add(new SecurityReference("Authorization", authorizationScopes));return securityReferences;}private ApiInfo apiInfo(SwaggerProperties swaggerProperties){return new ApiInfoBuilder().title(swaggerProperties.getTitle()).description(swaggerProperties.getDescription()).license(swaggerProperties.getLicense()).licenseUrl(swaggerProperties.getLicenseUrl()).termsOfServiceUrl(swaggerProperties.getTermsOfServiceUrl()).contact(new Contact(swaggerProperties.getContact().getName(), swaggerProperties.getContact().getUrl(), swaggerProperties.getContact().getEmail())).version(swaggerProperties.getVersion()).build();}
}

在这里插入图片描述
在查询接口以上两个字段deptNameorderNum不会被识别成必填字段

(2)在以上基础加入knife4j依赖

<!-- knife4j--><dependency><groupId>com.github.xiaoymin</groupId><artifactId>knife4j-spring-boot-starter</artifactId><version>3.0.2</version></dependency>


在查询接口以上两个字段deptNameorderNum会被识别成必填字段。


原因分析:

应该是swagger对注解@NotBlank(message = "部门名称不能为空")没有生效。


解决方案:

目前还不知道为什么swagger没有对注解生效,也没有验证这个必填问题是否对前端接口调用有影响,期待大佬的解疑!!!

http://www.dt0577.cn/news/5864.html

相关文章:

  • wordpress小工具功能seo 优化 服务
  • 企业网站建设合同企业管理系统
  • 移动网站设计手机百度识图网页版入口
  • 丹阳网站建设价格苏州seo关键词优化方法
  • 东莞做网站多少钱百度知道首页登录入口
  • 模板官网新余seo
  • 上海排名十大装潢公司网站优化排名服务
  • 如何设置wordpress会员注册页咸宁网站seo
  • 烟台网站建设设计公司南昌seo排名公司
  • 腾讯云官网入口aso优化服务站
  • 资讯网站怎么做陕西企业网站建设
  • 找人做任务网站有哪些seo编辑是干什么的
  • 建设一个网站需要什么人员2022适合小学生的简短新闻摘抄
  • 做电影网站怎么盈利百度笔记排名优化
  • 网站里的动态是如何制作昨日凌晨北京突然宣布重大消息
  • 台州网站专业制作怎样做网站平台
  • ui设计师mike个人网站关键时刻
  • 网站建站网站91955怎么自己刷推广链接
  • 许昌住房和城乡建设部网站全国十大教育机构
  • 一起做业英语网站b站不收费网站
  • 新网站怎么做排名青岛百度代理公司
  • 网站设计风格及特点广州seo顾问
  • 网站建设要考虑的问题谷歌商店官网下载
  • 别人用我公司权限做网站seo网站排名优化工具
  • 武汉营销型网站制作公司百度官网首页登陆
  • 响应式网站建设哪里有推广排名seo
  • 网站程序语言网站免费网站免费
  • 小程序网站开发者利免费视频外链生成推荐
  • 淘宝客怎样做自己的网站推广代运营公司前十名
  • 网站建设哪个公司好知乎微信公众号营销