Spring boot Kotlin中的Spring RequestParam验证不起作用
我试图在Kotlin中验证Spring boot Kotlin中的Spring RequestParam验证不起作用,spring-boot,kotlin,Spring Boot,Kotlin,我试图在Kotlin中验证@RequestParam,但是它不起作用。目前我正在使用Kotlin1.4.20、SpringBoot2.3.5和Java1.8 这是我的控制器: @Validated @RestController @RequestMapping("api/v1/") class myController{ @GetMapping("/age", produces = [MediaType.APPLICATION_JSON_VALU
@RequestParam
,但是它不起作用。目前我正在使用Kotlin1.4.20、SpringBoot2.3.5和Java1.8
这是我的控制器:
@Validated
@RestController
@RequestMapping("api/v1/")
class myController{
@GetMapping("/age", produces = [MediaType.APPLICATION_JSON_VALUE])
fun findArticlesByAge(@RequestParam @Valid @Min(6) age: Int): ResponseEntity<Article> =
ResponseEntity
.ok()
.body(Article())
}
答复:
200
这是一个简单的验证,它不起作用,但是我想通过自定义注释和
ConstraintValidator
进行更复杂的验证。如果我使用简单的case@Min(6)
,它可能也会开始使用自定义注释。因此缺少一个依赖项:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
org.springframework.boot
弹簧启动启动器验证
我添加了这个,验证开始工作。但是,它会在验证消息中抛出500个内部服务器错误,该错误可由
ControllerAdvice
修复,因此缺少依赖项:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
org.springframework.boot
弹簧启动启动器验证
我添加了这个,验证开始工作。但是,它会在验证消息中抛出500个内部服务器错误,这可以由ControllerAdvice
修复
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>