美文网首页
Springboot Controller单参数校验

Springboot Controller单参数校验

作者: seawish | 来源:发表于2019-07-19 20:34 被阅读0次

Springboot使用JSR-303 Validation进行验证,大部分博客都只提及对Controller中的dto对象进行属性校验。本文是介绍如何对Controller中的方法的单一参数进行校验,步骤如下。

1. Controller添加注解@Validated

@RestController
@RequestMapping("/test")
@Validated
public class TestController {}

2. 单一参数校验

使用@Min等标签校验参数。

    @PostMapping("/list")
    @ResponseBody
    public Result<String> getBookList(@Min(1) Integer pageNum,@Min(1) Integer pageSize, @RequestBody @Validated TestDto dto) {
        ...
    }

参考文献

Bean Validation 技术规范特性概述
)


本文作者: seawish
版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 3.0 许可协议。转载请注明出处!

相关文章

网友评论

      本文标题:Springboot Controller单参数校验

      本文链接:https://www.haomeiwen.com/subject/slcelctx.html