我收到规范中没有定义的操作!在 spring boot 上加载 swagger-ui 时
以下是代码详细信息:
pom.xml
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>1.4.8</version>
</dependency>
On my main file,
@OpenAPIDefinition(
info = @Info(
title = "RESTAPI",
//version = "${app.version}",
description = "svsjsjj ssksj",
contact = @Contact(
name = "bajaj",
url = "https://jhakja.com"
)
)
)
@SpringBootApplication
@EnableSwagger2
@ComponentScan(basePackages = { "io.swagger", "io.swagger.api" , "io.swagger.configuration"})
public class Swagger2SpringBoot extends SpringBootServletInitializer implements CommandLineRunner {
// I have sqlitcode + Date and time code,
public …
Run Code Online (Sandbox Code Playgroud) 我DateTimeFormatterRegistrar
在我的班级中注册了一个WebMvcConfigurer
这样的实现:
@Override
public void addFormatters(FormatterRegistry registry) {
DateTimeFormatterRegistrar registrar = new DateTimeFormatterRegistrar();
registrar.setUseIsoFormat(true);
registrar.registerFormatters(registry);
}
Run Code Online (Sandbox Code Playgroud)
在其余控制器中,我尝试将客户端GET
参数解析为一个对象:
@GetMapping("/api/url/path")
public APIResponse getPersonAttendList(@Valid SampleVO vo){}
Run Code Online (Sandbox Code Playgroud)
SampleVO
包括字段LocalDateTime time
。如果客户端提供了错误的time
参数格式,绑定将失败。服务器将返回 500,并像这样打印一些日志:
>ERROR o.a.c.c.C.[.[.[.[dispatcherServlet] 175 - Servlet.service() for
servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed;
nested exception is java.time.format.DateTimeParseException
Run Code Online (Sandbox Code Playgroud)
我的问题是,如何捕获此异常并将 400 返回给客户端?它似乎ControllerAdvice
不起作用。
当我尝试将一个实体与多个实体映射时,我收到此错误..
/// 这是我的候选人资料实体/////////
包 com.demo.project.premiumjobportal.model; 导入 java.io.Serializable; 导入 java.util.List; 导入 javax.persistence.CascadeType; 导入 javax.persistence.Column; 导入 javax.persistence.Entity; 导入 javax.persistence.FetchType; 导入 javax.persistence.GeneratedValue; 导入 javax.persistence.Id; 导入 javax.persistence.ManyToOne; 导入 javax.persistence.OneToMany; 导入 javax.persistence.Table; 导入 javax.validation.constraints.NotNull; 导入 javax.xml.bind.annotation.XmlRootElement; 导入 com.fasterxml.jackson.annotation.JsonBackReference; 导入 com.fasterxml.jackson.annotation.JsonIgnoreProperties; //候选明细表:主表 @实体 @Table(name="candidate_profile") @JsonIgnoreProperties({"hibernateLazyInitializer", "handler"}) @XmlRootElement 公共类 CandidateProfile 实现了 Serializable { private static final long serialVersionUID = 1L; @ID @GeneratedValue 私有整数 ID; @NotNull @Column(name="first_name", 长度 = 25) 私人字符串名字; @NotNull @Column(name="last_name", 长度 = 25) 私人字符串姓氏; @NotNull @Column(名称=“用户名”,长度= 50) 私人字符串用户名; @Column(name="alt_email_id", 长度 = 50) 私人字符串alternateEmailId; @NotNull @Column(name="mobile_no", …
在collections类中有一个方法sort()用于排序集合元素,但我有一个疑问,内部使用哪种排序算法对元素进行排序.我用Google搜索但没有得到正确答案.请帮帮我 .