How to validate Spring MVC @PathVariable values?

前端 未结 6 1844
难免孤独
难免孤独 2020-12-09 03:28

For a simple RESTful JSON api implemented in Spring MVC, can I use Bean Validation (JSR-303) to validate the path variables passed into the handler method?

For examp

6条回答
  •  佛祖请我去吃肉
    2020-12-09 04:26

    Spring does not support @javax.validation.Valid on @PathVariable annotated parameters in handler methods. There was an Improvement request, but it is still unresolved.

    Your best bet is to just do your custom validation in the handler method body or consider using org.springframework.validation.annotation.Validated as suggested in other answers.

提交回复
热议问题