亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

來自 javax.validation.constraints 的注釋不起作用(忽略)

來自 javax.validation.constraints 的注釋不起作用(忽略)

www說 2023-04-26 13:47:57
我正在嘗試使用 javax 約束在運行邏輯之前預先驗證請求內容。我已經嘗試了任何可能的解決方案,但仍然無法在 Spring 引導中使用 javax 注釋。import javax.validation.constraints.Minimport javax.validation.constraints.Patterndata class LoginRequest (        @Credential //Custom constraint that works just fine        val credential: String,        @Min(value= 5)        val password: String,        @Pattern(regexp = Constants.Regex.DEVICE_ID_REGEX, message = "Invalid device ID")        val device: String): Serializable這是 pom.xml 的一部分<dependency>    <groupId>org.springframework.boot</groupId>    <artifactId>spring-boot-starter-web</artifactId></dependency><dependency>    <groupId>org.springframework.boot</groupId>    <artifactId>spring-boot-starter-data-jpa</artifactId></dependency>..<dependency>    <groupId>javax.validation</groupId>    <artifactId>validation-api</artifactId>    <version>2.0.1.Final</version></dependency><dependency>    <groupId>org.hibernate.validator</groupId>    <artifactId>hibernate-validator</artifactId>    <version>6.0.17.Final</version></dependency><dependency>    <groupId>org.hibernate.validator</groupId>    <artifactId>hibernate-validator-annotation-processor</artifactId>    <version>6.0.17.Final</version></dependency>這是控制器import javax.validation.Valid@PostMapping("/login")    fun userLoginEndpoint(@Valid @RequestBody loginRequest: LoginRequest): ResponseEntity<User> {        return authService.loginUser(loginRequest)                ?.let{ ResponseEntity(it, HttpStatus.ACCEPTED)}                ?: ResponseEntity.status(HttpStatus.UNAUTHORIZED).build()    }難道我做錯了什么?
查看完整描述

1 回答

?
qq_笑_17

TA貢獻1818條經驗 獲得超7個贊

@Min(value= 5)(當然還有其他驗證注釋)替換為@field:Min(value= 5).


查看完整回答
反對 回復 2023-04-26
  • 1 回答
  • 0 關注
  • 383 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號