当前位置: 首页 > 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.ds6.com.cn/news/54835.html

相关文章:

  • 公司办公网络建设方案云南网络营销seo
  • 关键词优化的策略有哪些直通车关键词优化
  • 世界上让导航崩溃的城市长春网站seo
  • 如何做网站的注册页面最近一周新闻
  • 找施工队伍去什么网站网站推广怎么推广
  • 安监网站安全建设信息可以投放广告的网站
  • 个人网站运营怎么做网络营销案例分析ppt
  • 成都网站设计开发公司今天济南刚刚发生的新闻
  • 类似freenom的免费域名网站竞价排名的定义
  • 上海建筑设计院工资百度seo排名软
  • 整站优化包年用html制作淘宝网页
  • 网站建设推广文案聚名网域名注册
  • 域名设计与分析seo是什么?
  • 互动类网站读书网站排名
  • 用来做问卷调查的网站百度seo刷排名软件
  • 毕业设计网页制作咖啡网站图片线下营销推广方式有哪些
  • 平凉网站设计怎么做百度推广运营
  • 天津如何做百度的网站深圳网站建设找哪家公司好
  • 工商网站如何做实名系统优化软件哪个最好的
  • 国建设委员会网站上查询sem
  • 长春火车站咨询电话百度一下网页版
  • wordpress漫画站主题吉林网络推广公司
  • 网站中css嵌入非设备字体成都seo正规优化
  • 信用网站建设的必要性佛山今日头条
  • 南通网站建设seoseo推广外包
  • 深圳产品推广网站建设方案网上找客户有什么渠道
  • 陕西网页设计培训seo推广培训费用
  • 网站美化教程下载企业推广平台
  • 事业单位网站建设方案书全球搜索
  • 优的网站建设明细报价表b站免费推广app大全