| |
| <!DOCTYPE HTML> |
| <html lang="" > |
| <head> |
| <meta charset="UTF-8"> |
| <meta content="text/html; charset=utf-8" http-equiv="Content-Type"> |
| <title>4.15 参数验证 · GitBook</title> |
| <meta http-equiv="X-UA-Compatible" content="IE=edge" /> |
| <meta name="description" content=""> |
| <meta name="generator" content="GitBook 3.2.2"> |
| |
| |
| |
| |
| <link rel="stylesheet" href="../gitbook/style.css"> |
| |
| |
| |
| |
| <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css"> |
| |
| |
| |
| <link rel="stylesheet" href="../gitbook/gitbook-plugin-search/search.css"> |
| |
| |
| |
| <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css"> |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| <meta name="HandheldFriendly" content="true"/> |
| <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no"> |
| <meta name="apple-mobile-web-app-capable" content="yes"> |
| <meta name="apple-mobile-web-app-status-bar-style" content="black"> |
| <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png"> |
| <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon"> |
| |
| |
| <link rel="next" href="结果缓存.html" /> |
| |
| |
| <link rel="prev" href="分组聚合.html" /> |
| |
| |
| </head> |
| <body> |
| |
| <div class="book"> |
| <div class="book-summary"> |
| |
| |
| <div id="book-search-input" role="search"> |
| <input type="text" placeholder="Type to search" /> |
| </div> |
| |
| |
| <nav role="navigation"> |
| |
| |
| |
| <ul class="summary"> |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| <li class="chapter " data-level="1.1" data-path="../"> |
| |
| <a href="../"> |
| |
| |
| Introduction |
| |
| </a> |
| |
| |
| |
| </li> |
| |
| <li class="chapter " data-level="1.2" > |
| |
| <span> |
| |
| |
| 1 入门 |
| |
| </span> |
| |
| |
| |
| <ul class="articles"> |
| |
| |
| <li class="chapter " data-level="1.2.1" data-path="../preface/background.html"> |
| |
| <a href="../preface/background.html"> |
| |
| |
| 1.1 背景 |
| |
| </a> |
| |
| |
| |
| </li> |
| |
| <li class="chapter " data-level="1.2.2" data-path="../preface/requirements.html"> |
| |
| <a href="../preface/requirements.html"> |
| |
| |
| 1.2 需求 |
| |
| </a> |
| |
| |
| |
| </li> |
| |
| <li class="chapter " data-level="1.2.3" data-path="../preface/architacture.html"> |
| |
| <a href="../preface/architacture.html"> |
| |
| |
| 1.3 架构 |
| |
| </a> |
| |
| |
| |
| </li> |
| |
| <li class="chapter " data-level="1.2.4" data-path="../preface/usage.html"> |
| |
| <a href="../preface/usage.html"> |
| |
| |
| 1.4 用法 |
| |
| </a> |
| |
| |
| |
| </li> |
| |
| |
| </ul> |
| |
| </li> |
| |
| <li class="chapter " data-level="1.3" > |
| |
| <span> |
| |
| |
| 2 快速启动 |
| |
| </span> |
| |
| |
| |
| <ul class="articles"> |
| |
| |
| <li class="chapter " data-level="1.3.1" data-path="../dependencies/dependencies.html"> |
| |
| <a href="../dependencies/dependencies.html"> |
| |
| |
| 2.1 依赖 |
| |
| </a> |
| |
| |
| |
| </li> |
| |
| <li class="chapter " data-level="1.3.2" data-path="../maturity/maturity.html"> |
| |
| <a href="../maturity/maturity.html"> |
| |
| |
| 2.2 成熟度 |
| |
| </a> |
| |
| |
| |
| </li> |
| |
| |
| </ul> |
| |
| </li> |
| |
| <li class="chapter " data-level="1.4" > |
| |
| <span> |
| |
| |
| 3 配置 |
| |
| </span> |
| |
| |
| |
| <ul class="articles"> |
| |
| |
| <li class="chapter " data-level="1.4.1" data-path="../configuration/xml.html"> |
| |
| <a href="../configuration/xml.html"> |
| |
| |
| 3.1 XML配置 |
| |
| </a> |
| |
| |
| |
| </li> |
| |
| <li class="chapter " data-level="1.4.2" data-path="../configuration/properties.html"> |
| |
| <a href="../configuration/properties.html"> |
| |
| |
| 3.2 属性配置 |
| |
| </a> |
| |
| |
| |
| </li> |
| |
| <li class="chapter " data-level="1.4.3" data-path="../configuration/api.html"> |
| |
| <a href="../configuration/api.html"> |
| |
| |
| 3.3 API配置 |
| |
| </a> |
| |
| |
| |
| </li> |
| |
| <li class="chapter " data-level="1.4.4" data-path="../configuration/annotation.html"> |
| |
| <a href="../configuration/annotation.html"> |
| |
| |
| 3.4 注解配置 |
| |
| </a> |
| |
| |
| |
| </li> |
| |
| |
| </ul> |
| |
| </li> |
| |
| <li class="chapter " data-level="1.5" > |
| |
| <span> |
| |
| |
| 4 示例 |
| |
| </span> |
| |
| |
| |
| <ul class="articles"> |
| |
| |
| <li class="chapter " data-level="1.5.1" data-path="启动时检查.html"> |
| |
| <a href="启动时检查.html"> |
| |
| |
| 4.1 启动时检查 |
| |
| </a> |
| |
| |
| |
| </li> |
| |
| <li class="chapter " data-level="1.5.2" data-path="集群容错.html"> |
| |
| <a href="集群容错.html"> |
| |
| |
| 4.2 集群容错 |
| |
| </a> |
| |
| |
| |
| </li> |
| |
| <li class="chapter " data-level="1.5.3" data-path="负载均衡.html"> |
| |
| <a href="负载均衡.html"> |
| |
| |
| 4.3 负载均衡 |
| |
| </a> |
| |
| |
| |
| </li> |
| |
| <li class="chapter " data-level="1.5.4" data-path="线程模型.html"> |
| |
| <a href="线程模型.html"> |
| |
| |
| 4.4 线程模型 |
| |
| </a> |
| |
| |
| |
| </li> |
| |
| <li class="chapter " data-level="1.5.5" data-path="直连提供者.html"> |
| |
| <a href="直连提供者.html"> |
| |
| |
| 4.5 直连提供者 |
| |
| </a> |
| |
| |
| |
| </li> |
| |
| <li class="chapter " data-level="1.5.6" data-path="只订阅.html"> |
| |
| <a href="只订阅.html"> |
| |
| |
| 4.6 只订阅 |
| |
| </a> |
| |
| |
| |
| </li> |
| |
| <li class="chapter " data-level="1.5.7" data-path="只注册.html"> |
| |
| <a href="只注册.html"> |
| |
| |
| 4.7 只注册 |
| |
| </a> |
| |
| |
| |
| </li> |
| |
| <li class="chapter " data-level="1.5.8" data-path="静态服务.html"> |
| |
| <a href="静态服务.html"> |
| |
| |
| 4.8 静态服务 |
| |
| </a> |
| |
| |
| |
| </li> |
| |
| <li class="chapter " data-level="1.5.9" data-path="多协议.html"> |
| |
| <a href="多协议.html"> |
| |
| |
| 4.9 多协议 |
| |
| </a> |
| |
| |
| |
| </li> |
| |
| <li class="chapter " data-level="1.5.10" data-path="多注册中心.html"> |
| |
| <a href="多注册中心.html"> |
| |
| |
| 4.10 多注册中心 |
| |
| </a> |
| |
| |
| |
| </li> |
| |
| <li class="chapter " data-level="1.5.11" data-path="服务分组.html"> |
| |
| <a href="服务分组.html"> |
| |
| |
| 4.11 服务分组 |
| |
| </a> |
| |
| |
| |
| </li> |
| |
| <li class="chapter " data-level="1.5.12" data-path="多版本.html"> |
| |
| <a href="多版本.html"> |
| |
| |
| 4.13 多版本 |
| |
| </a> |
| |
| |
| |
| </li> |
| |
| <li class="chapter " data-level="1.5.13" data-path="分组聚合.html"> |
| |
| <a href="分组聚合.html"> |
| |
| |
| 4.14 分组聚合 |
| |
| </a> |
| |
| |
| |
| </li> |
| |
| <li class="chapter active" data-level="1.5.14" data-path="参数验证.html"> |
| |
| <a href="参数验证.html"> |
| |
| |
| 4.15 参数验证 |
| |
| </a> |
| |
| |
| |
| </li> |
| |
| <li class="chapter " data-level="1.5.15" data-path="结果缓存.html"> |
| |
| <a href="结果缓存.html"> |
| |
| |
| 4.16 结果缓存 |
| |
| </a> |
| |
| |
| |
| </li> |
| |
| <li class="chapter " data-level="1.5.16" data-path="泛化引用.html"> |
| |
| <a href="泛化引用.html"> |
| |
| |
| 4.17 泛化引用 |
| |
| </a> |
| |
| |
| |
| </li> |
| |
| <li class="chapter " data-level="1.5.17" data-path="泛化实现.html"> |
| |
| <a href="泛化实现.html"> |
| |
| |
| 4.18 泛化实现 |
| |
| </a> |
| |
| |
| |
| </li> |
| |
| <li class="chapter " data-level="1.5.18" data-path="回声测试.html"> |
| |
| <a href="回声测试.html"> |
| |
| |
| 4.19 回声测试 |
| |
| </a> |
| |
| |
| |
| </li> |
| |
| <li class="chapter " data-level="1.5.19" data-path="上下文信息.html"> |
| |
| <a href="上下文信息.html"> |
| |
| |
| 4.20 上下文信息 |
| |
| </a> |
| |
| |
| |
| </li> |
| |
| <li class="chapter " data-level="1.5.20" data-path="隐式参数.md"> |
| |
| <span> |
| |
| |
| 4.21 隐式参数 |
| |
| </a> |
| |
| |
| |
| </li> |
| |
| <li class="chapter " data-level="1.5.21" data-path="异步调用.html"> |
| |
| <a href="异步调用.html"> |
| |
| |
| 4.22 异步调用 |
| |
| </a> |
| |
| |
| |
| </li> |
| |
| <li class="chapter " data-level="1.5.22" data-path="本地调用.html"> |
| |
| <a href="本地调用.html"> |
| |
| |
| 4.23 本地调用 |
| |
| </a> |
| |
| |
| |
| </li> |
| |
| <li class="chapter " data-level="1.5.23" data-path="参数回调.html"> |
| |
| <a href="参数回调.html"> |
| |
| |
| 4.24 参数回调 |
| |
| </a> |
| |
| |
| |
| </li> |
| |
| <li class="chapter " data-level="1.5.24" data-path="事件通知.html"> |
| |
| <a href="事件通知.html"> |
| |
| |
| 4.25 事件通知 |
| |
| </a> |
| |
| |
| |
| </li> |
| |
| <li class="chapter " data-level="1.5.25" data-path="本地存根.html"> |
| |
| <a href="本地存根.html"> |
| |
| |
| 4.26 本地存根 |
| |
| </a> |
| |
| |
| |
| </li> |
| |
| <li class="chapter " data-level="1.5.26" data-path="本地伪装.html"> |
| |
| <a href="本地伪装.html"> |
| |
| |
| 4.27 本地伪装 |
| |
| </a> |
| |
| |
| |
| </li> |
| |
| <li class="chapter " data-level="1.5.27" data-path="延迟暴露.html"> |
| |
| <a href="延迟暴露.html"> |
| |
| |
| 4.28 延迟暴露 |
| |
| </a> |
| |
| |
| |
| </li> |
| |
| <li class="chapter " data-level="1.5.28" data-path="并发控制.html"> |
| |
| <a href="并发控制.html"> |
| |
| |
| 4.29 并发控制 |
| |
| </a> |
| |
| |
| |
| </li> |
| |
| <li class="chapter " data-level="1.5.29" data-path="连接控制.html"> |
| |
| <a href="连接控制.html"> |
| |
| |
| 4.30 连接控制 |
| |
| </a> |
| |
| |
| |
| </li> |
| |
| <li class="chapter " data-level="1.5.30" data-path="延迟连接.html"> |
| |
| <a href="延迟连接.html"> |
| |
| |
| 4.31 延迟连接 |
| |
| </a> |
| |
| |
| |
| </li> |
| |
| <li class="chapter " data-level="1.5.31" data-path="粘滞连接.html"> |
| |
| <a href="粘滞连接.html"> |
| |
| |
| 4.32 粘滞连接 |
| |
| </a> |
| |
| |
| |
| </li> |
| |
| <li class="chapter " data-level="1.5.32" data-path="令牌验证.html"> |
| |
| <a href="令牌验证.html"> |
| |
| |
| 4.33 令牌验证 |
| |
| </a> |
| |
| |
| |
| </li> |
| |
| <li class="chapter " data-level="1.5.33" data-path="路由规则.html"> |
| |
| <a href="路由规则.html"> |
| |
| |
| 4.34 路由规则 |
| |
| </a> |
| |
| |
| |
| </li> |
| |
| <li class="chapter " data-level="1.5.34" data-path="配置规则.html"> |
| |
| <a href="配置规则.html"> |
| |
| |
| 4.35 配置规则 |
| |
| </a> |
| |
| |
| |
| </li> |
| |
| <li class="chapter " data-level="1.5.35" data-path="服务降级.html"> |
| |
| <a href="服务降级.html"> |
| |
| |
| 4.36 服务降级 |
| |
| </a> |
| |
| |
| |
| </li> |
| |
| <li class="chapter " data-level="1.5.36" data-path="优雅停机.html"> |
| |
| <a href="优雅停机.html"> |
| |
| |
| 4.37 优雅停机 |
| |
| </a> |
| |
| |
| |
| </li> |
| |
| <li class="chapter " data-level="1.5.37" data-path="主机绑定.html"> |
| |
| <a href="主机绑定.html"> |
| |
| |
| 4.38 主机绑定 |
| |
| </a> |
| |
| |
| |
| </li> |
| |
| <li class="chapter " data-level="1.5.38" data-path="日志适配.html"> |
| |
| <a href="日志适配.html"> |
| |
| |
| 4.39 日志适配 |
| |
| </a> |
| |
| |
| |
| </li> |
| |
| <li class="chapter " data-level="1.5.39" data-path="访问日志.html"> |
| |
| <a href="访问日志.html"> |
| |
| |
| 4.40 访问日志 |
| |
| </a> |
| |
| |
| |
| </li> |
| |
| <li class="chapter " data-level="1.5.40" data-path="服务容器.html"> |
| |
| <a href="服务容器.html"> |
| |
| |
| 4.41 服务容器 |
| |
| </a> |
| |
| |
| |
| </li> |
| |
| <li class="chapter " data-level="1.5.41" data-path="ReferenceConfig缓存.html"> |
| |
| <a href="ReferenceConfig缓存.html"> |
| |
| |
| 4.42 Reference Config缓存 |
| |
| </a> |
| |
| |
| |
| </li> |
| |
| <li class="chapter " data-level="1.5.42" data-path="分布式事务.html"> |
| |
| <a href="分布式事务.html"> |
| |
| |
| 4.43 分布式事务 |
| |
| </a> |
| |
| |
| |
| </li> |
| |
| <li class="chapter " data-level="1.5.43" data-path="../reference-apiconf/api.html"> |
| |
| <a href="../reference-apiconf/api.html"> |
| |
| |
| 5 API参考手册 |
| |
| </a> |
| |
| |
| |
| </li> |
| |
| |
| </ul> |
| |
| </li> |
| |
| <li class="chapter " data-level="1.6" data-path="../reference-xmlconf/introduction.html"> |
| |
| <a href="../reference-xmlconf/introduction.html"> |
| |
| |
| 5 schema配置参考手册 |
| |
| </a> |
| |
| |
| |
| <ul class="articles"> |
| |
| |
| <li class="chapter " data-level="1.6.1" data-path="../reference-xmlconf/dubbo-service.html"> |
| |
| <a href="../reference-xmlconf/dubbo-service.html"> |
| |
| |
| 5.1 dubbo:service |
| |
| </a> |
| |
| |
| |
| </li> |
| |
| <li class="chapter " data-level="1.6.2" data-path="../reference-xmlconf/dubbo-reference.html"> |
| |
| <a href="../reference-xmlconf/dubbo-reference.html"> |
| |
| |
| 5.2 dubbo:reference |
| |
| </a> |
| |
| |
| |
| </li> |
| |
| <li class="chapter " data-level="1.6.3" data-path="../reference-xmlconf/dubbo-protocol.html"> |
| |
| <a href="../reference-xmlconf/dubbo-protocol.html"> |
| |
| |
| 5.3 dubbo:protocol |
| |
| </a> |
| |
| |
| |
| </li> |
| |
| <li class="chapter " data-level="1.6.4" data-path="../reference-xmlconf/dubbo-registry.html"> |
| |
| <a href="../reference-xmlconf/dubbo-registry.html"> |
| |
| |
| 5.4 dubbo:registry |
| |
| </a> |
| |
| |
| |
| </li> |
| |
| <li class="chapter " data-level="1.6.5" data-path="../reference-xmlconf/dubbo-monitor.html"> |
| |
| <a href="../reference-xmlconf/dubbo-monitor.html"> |
| |
| |
| 5.5 dubbo:monitor |
| |
| </a> |
| |
| |
| |
| </li> |
| |
| <li class="chapter " data-level="1.6.6" data-path="../reference-xmlconf/dubbo-application.html"> |
| |
| <a href="../reference-xmlconf/dubbo-application.html"> |
| |
| |
| 5.6 dubbo:application |
| |
| </a> |
| |
| |
| |
| </li> |
| |
| <li class="chapter " data-level="1.6.7" data-path="../reference-xmlconf/dubbo-module.html"> |
| |
| <a href="../reference-xmlconf/dubbo-module.html"> |
| |
| |
| 5.7 dubbo:module |
| |
| </a> |
| |
| |
| |
| </li> |
| |
| <li class="chapter " data-level="1.6.8" data-path="../reference-xmlconf/dubbo-provider.html"> |
| |
| <a href="../reference-xmlconf/dubbo-provider.html"> |
| |
| |
| 5.8 dubbo:provider |
| |
| </a> |
| |
| |
| |
| </li> |
| |
| <li class="chapter " data-level="1.6.9" data-path="../reference-xmlconf/dubbo-consumer.html"> |
| |
| <a href="../reference-xmlconf/dubbo-consumer.html"> |
| |
| |
| 5.9 dubbo:consumer |
| |
| </a> |
| |
| |
| |
| </li> |
| |
| <li class="chapter " data-level="1.6.10" data-path="../reference-xmlconf/dubbo-method.html"> |
| |
| <a href="../reference-xmlconf/dubbo-method.html"> |
| |
| |
| 5.10 dubbo:method |
| |
| </a> |
| |
| |
| |
| </li> |
| |
| <li class="chapter " data-level="1.6.11" data-path="../reference-xmlconf/dubbo-argument.html"> |
| |
| <a href="../reference-xmlconf/dubbo-argument.html"> |
| |
| |
| 5.11 dubbo:argument |
| |
| </a> |
| |
| |
| |
| </li> |
| |
| <li class="chapter " data-level="1.6.12" data-path="../reference-xmlconf/dubbo-parameter.html"> |
| |
| <a href="../reference-xmlconf/dubbo-parameter.html"> |
| |
| |
| 5.12 dubbo:parameter |
| |
| </a> |
| |
| |
| |
| </li> |
| |
| |
| </ul> |
| |
| </li> |
| |
| <li class="chapter " data-level="1.7" data-path="../reference-protocol/introduction.html"> |
| |
| <a href="../reference-protocol/introduction.html"> |
| |
| |
| 6 协议参考手册 |
| |
| </a> |
| |
| |
| |
| <ul class="articles"> |
| |
| |
| <li class="chapter " data-level="1.7.1" data-path="../reference-protocol/dubbo.html"> |
| |
| <a href="../reference-protocol/dubbo.html"> |
| |
| |
| 6.1 dubbo:// |
| |
| </a> |
| |
| |
| |
| </li> |
| |
| <li class="chapter " data-level="1.7.2" data-path="../reference-protocol/rmi.html"> |
| |
| <a href="../reference-protocol/rmi.html"> |
| |
| |
| 6.2 rmi// |
| |
| </a> |
| |
| |
| |
| </li> |
| |
| <li class="chapter " data-level="1.7.3" data-path="../reference-protocol/hessian.html"> |
| |
| <a href="../reference-protocol/hessian.html"> |
| |
| |
| 6.3 hessian:// |
| |
| </a> |
| |
| |
| |
| </li> |
| |
| <li class="chapter " data-level="1.7.4" data-path="../reference-protocol/http.html"> |
| |
| <a href="../reference-protocol/http.html"> |
| |
| |
| 6.4 http:// |
| |
| </a> |
| |
| |
| |
| </li> |
| |
| <li class="chapter " data-level="1.7.5" data-path="../reference-protocol/webservice.html"> |
| |
| <a href="../reference-protocol/webservice.html"> |
| |
| |
| 6.5 webservice:// |
| |
| </a> |
| |
| |
| |
| </li> |
| |
| <li class="chapter " data-level="1.7.6" data-path="../reference-protocol/thrift.html"> |
| |
| <a href="../reference-protocol/thrift.html"> |
| |
| |
| 6.6 thrift:// |
| |
| </a> |
| |
| |
| |
| </li> |
| |
| <li class="chapter " data-level="1.7.7" data-path="../reference-protocol/memcached.html"> |
| |
| <a href="../reference-protocol/memcached.html"> |
| |
| |
| 6.7 memcached:// |
| |
| </a> |
| |
| |
| |
| </li> |
| |
| <li class="chapter " data-level="1.7.8" data-path="../reference-protocol/redis.html"> |
| |
| <a href="../reference-protocol/redis.html"> |
| |
| |
| 6.8 redis:// |
| |
| </a> |
| |
| |
| |
| </li> |
| |
| |
| </ul> |
| |
| </li> |
| |
| <li class="chapter " data-level="1.8" data-path="../reference-registry/introduction.html"> |
| |
| <a href="../reference-registry/introduction.html"> |
| |
| |
| 7 注册中心参考手册 |
| |
| </a> |
| |
| |
| |
| <ul class="articles"> |
| |
| |
| <li class="chapter " data-level="1.8.1" data-path="../reference-registry/multicast.html"> |
| |
| <a href="../reference-registry/multicast.html"> |
| |
| |
| 7.1 Multicast注册中心 |
| |
| </a> |
| |
| |
| |
| </li> |
| |
| <li class="chapter " data-level="1.8.2" data-path="../reference-registry/zookeeper.html"> |
| |
| <a href="../reference-registry/zookeeper.html"> |
| |
| |
| 7.2 Zookeeper注册中心 |
| |
| </a> |
| |
| |
| |
| </li> |
| |
| <li class="chapter " data-level="1.8.3" data-path="../reference-registry/redis.html"> |
| |
| <a href="../reference-registry/redis.html"> |
| |
| |
| 7.3 Redis注册中心 |
| |
| </a> |
| |
| |
| |
| </li> |
| |
| <li class="chapter " data-level="1.8.4" data-path="../reference-registry/simple.html"> |
| |
| <a href="../reference-registry/simple.html"> |
| |
| |
| 7.4 Simple注册中心 |
| |
| </a> |
| |
| |
| |
| </li> |
| |
| |
| </ul> |
| |
| </li> |
| |
| <li class="chapter " data-level="1.9" data-path="../reference-telnet/telnet.html"> |
| |
| <a href="../reference-telnet/telnet.html"> |
| |
| |
| 8 telnet命令参考手册 |
| |
| </a> |
| |
| |
| |
| </li> |
| |
| <li class="chapter " data-level="1.10" data-path="../reference-maven/maven.html"> |
| |
| <a href="../reference-maven/maven.html"> |
| |
| |
| 9 maven插件参考手册 |
| |
| </a> |
| |
| |
| |
| </li> |
| |
| <li class="chapter " data-level="1.11" data-path="../best-practice.html"> |
| |
| <a href="../best-practice.html"> |
| |
| |
| 10 服务化最佳实践 |
| |
| </a> |
| |
| |
| |
| </li> |
| |
| <li class="chapter " data-level="1.12" data-path="../recommend.html"> |
| |
| <a href="../recommend.html"> |
| |
| |
| 11 推荐用法 |
| |
| </a> |
| |
| |
| |
| </li> |
| |
| <li class="chapter " data-level="1.13" data-path="../capacity-plan.html"> |
| |
| <a href="../capacity-plan.html"> |
| |
| |
| 12 容量规划 |
| |
| </a> |
| |
| |
| |
| </li> |
| |
| <li class="chapter " data-level="1.14" data-path="../benchmark.html"> |
| |
| <a href="../benchmark.html"> |
| |
| |
| 13 基准测试工具包 |
| |
| </a> |
| |
| |
| |
| </li> |
| |
| <li class="chapter " data-level="1.15" data-path="../perf-test.html"> |
| |
| <a href="../perf-test.html"> |
| |
| |
| 14 性能测试报告 |
| |
| </a> |
| |
| |
| |
| </li> |
| |
| <li class="chapter " data-level="1.16" data-path="../coveragence.html"> |
| |
| <a href="../coveragence.html"> |
| |
| |
| 15 测试覆盖率报告 |
| |
| </a> |
| |
| |
| |
| </li> |
| |
| |
| |
| |
| <li class="divider"></li> |
| |
| <li> |
| <a href="https://www.gitbook.com" target="blank" class="gitbook-link"> |
| Published with GitBook |
| </a> |
| </li> |
| </ul> |
| |
| |
| </nav> |
| |
| |
| </div> |
| |
| <div class="book-body"> |
| |
| <div class="body-inner"> |
| |
| |
| |
| <div class="book-header" role="navigation"> |
| |
| |
| <!-- Title --> |
| <h1> |
| <i class="fa fa-circle-o-notch fa-spin"></i> |
| <a href=".." >4.15 参数验证</a> |
| </h1> |
| </div> |
| |
| |
| |
| |
| <div class="page-wrapper" tabindex="-1" role="main"> |
| <div class="page-inner"> |
| |
| <div id="book-search-results"> |
| <div class="search-noresults"> |
| |
| <section class="normal markdown-section"> |
| |
| <blockquote> |
| <p><img src="../sources/images/check.gif" alt="warning">参数验证功能是基于 <a href="https://jcp.org/en/jsr/detail?id=303" target="_blank">JSR303</a> 实现的,用户只需标识JSR303标准的验证Annotation,并通过声明filter来实现验证。 </p> |
| <p><img src="../sources/images/warning-3.gif" alt="warning">2.1.0以上版本支持, 完整示例代码参见:<a href="https://github.com/alibaba/dubbo/tree/master/dubbo-test/dubbo-test-examples/src/main/java/com/alibaba/dubbo/examples/validation" target="_blank">https://github.com/alibaba/dubbo/tree/master/dubbo-test/dubbo-test-examples/src/main/java/com/alibaba/dubbo/examples/validation</a> </p> |
| </blockquote> |
| <p>验证方式可扩展,参见:<a href="dev-guide-spi-reference-manual#验证扩展">验证扩展</a></p> |
| <h5 id="参数标注示例">参数标注示例</h5> |
| <pre><code class="lang-java"> |
| <span class="hljs-keyword">import</span> java.io.Serializable; |
| <span class="hljs-keyword">import</span> java.util.Date; |
| |
| <span class="hljs-keyword">import</span> javax.validation.constraints.Future; |
| <span class="hljs-keyword">import</span> javax.validation.constraints.Max; |
| <span class="hljs-keyword">import</span> javax.validation.constraints.Min; |
| <span class="hljs-keyword">import</span> javax.validation.constraints.NotNull; |
| <span class="hljs-keyword">import</span> javax.validation.constraints.Past; |
| <span class="hljs-keyword">import</span> javax.validation.constraints.Pattern; |
| <span class="hljs-keyword">import</span> javax.validation.constraints.Size; |
| |
| <span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">ValidationParameter</span> <span class="hljs-keyword">implements</span> <span class="hljs-title">Serializable</span> </span>{ |
| |
| <span class="hljs-keyword">private</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">final</span> <span class="hljs-keyword">long</span> serialVersionUID = <span class="hljs-number">7158911668568000392L</span>; |
| |
| <span class="hljs-meta">@NotNull</span> <span class="hljs-comment">// 不允许为空</span> |
| <span class="hljs-meta">@Size</span>(min = <span class="hljs-number">1</span>, max = <span class="hljs-number">20</span>) <span class="hljs-comment">// 长度或大小范围</span> |
| <span class="hljs-keyword">private</span> String name; |
| |
| <span class="hljs-meta">@NotNull</span>(groups = ValidationService.Save.class) <span class="hljs-comment">// 保存时不允许为空,更新时允许为空 ,表示不更新该字段</span> |
| <span class="hljs-meta">@Pattern</span>(regexp = <span class="hljs-string">"^\\s*\\w+(?:\\.{0,1}[\\w-]+)*@[a-zA-Z0-9]+(?:[-.][a-zA-Z0-9]+)*\\.[a-zA-Z]+\\s*$"</span>) |
| <span class="hljs-keyword">private</span> String email; |
| |
| <span class="hljs-meta">@Min</span>(<span class="hljs-number">18</span>) <span class="hljs-comment">// 最小值</span> |
| <span class="hljs-meta">@Max</span>(<span class="hljs-number">100</span>) <span class="hljs-comment">// 最大值</span> |
| <span class="hljs-keyword">private</span> <span class="hljs-keyword">int</span> age; |
| |
| <span class="hljs-meta">@Past</span> <span class="hljs-comment">// 必须为一个过去的时间</span> |
| <span class="hljs-keyword">private</span> Date loginDate; |
| |
| <span class="hljs-meta">@Future</span> <span class="hljs-comment">// 必须为一个未来的时间</span> |
| <span class="hljs-keyword">private</span> Date expiryDate; |
| |
| <span class="hljs-function"><span class="hljs-keyword">public</span> String <span class="hljs-title">getName</span><span class="hljs-params">()</span> </span>{ |
| <span class="hljs-keyword">return</span> name; |
| } |
| |
| <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">setName</span><span class="hljs-params">(String name)</span> </span>{ |
| <span class="hljs-keyword">this</span>.name = name; |
| } |
| |
| <span class="hljs-function"><span class="hljs-keyword">public</span> String <span class="hljs-title">getEmail</span><span class="hljs-params">()</span> </span>{ |
| <span class="hljs-keyword">return</span> email; |
| } |
| |
| <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">setEmail</span><span class="hljs-params">(String email)</span> </span>{ |
| <span class="hljs-keyword">this</span>.email = email; |
| } |
| |
| <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">int</span> <span class="hljs-title">getAge</span><span class="hljs-params">()</span> </span>{ |
| <span class="hljs-keyword">return</span> age; |
| } |
| |
| <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">setAge</span><span class="hljs-params">(<span class="hljs-keyword">int</span> age)</span> </span>{ |
| <span class="hljs-keyword">this</span>.age = age; |
| } |
| |
| <span class="hljs-function"><span class="hljs-keyword">public</span> Date <span class="hljs-title">getLoginDate</span><span class="hljs-params">()</span> </span>{ |
| <span class="hljs-keyword">return</span> loginDate; |
| } |
| |
| <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">setLoginDate</span><span class="hljs-params">(Date loginDate)</span> </span>{ |
| <span class="hljs-keyword">this</span>.loginDate = loginDate; |
| } |
| |
| <span class="hljs-function"><span class="hljs-keyword">public</span> Date <span class="hljs-title">getExpiryDate</span><span class="hljs-params">()</span> </span>{ |
| <span class="hljs-keyword">return</span> expiryDate; |
| } |
| |
| <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">setExpiryDate</span><span class="hljs-params">(Date expiryDate)</span> </span>{ |
| <span class="hljs-keyword">this</span>.expiryDate = expiryDate; |
| } |
| |
| } |
| </code></pre> |
| <h5 id="分组验证示例">分组验证示例</h5> |
| <pre><code class="lang-java"><span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">interface</span> <span class="hljs-title">ValidationService</span> </span>{ <span class="hljs-comment">// 缺省可按服务接口区分验证场景,如:@NotNull(groups = ValidationService.class)</span> |
| |
| <span class="hljs-meta">@interface</span> Save{} <span class="hljs-comment">// 与方法同名接口,首字母大写,用于区分验证场景,如:@NotNull(groups = ValidationService.Save.class),可选</span> |
| <span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">save</span><span class="hljs-params">(ValidationParameter parameter)</span></span>; |
| <span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">update</span><span class="hljs-params">(ValidationParameter parameter)</span></span>; |
| } |
| </code></pre> |
| <h5 id="关联验证示例">关联验证示例</h5> |
| <pre><code class="lang-java"><span class="hljs-keyword">import</span> javax.validation.GroupSequence; |
| |
| <span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">interface</span> <span class="hljs-title">ValidationService</span> </span>{ |
| |
| <span class="hljs-meta">@GroupSequence</span>(Update.class) <span class="hljs-comment">// 同时验证Update组规则</span> |
| <span class="hljs-meta">@interface</span> Save{} |
| <span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">save</span><span class="hljs-params">(ValidationParameter parameter)</span></span>; |
| |
| <span class="hljs-meta">@interface</span> Update{} |
| <span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">update</span><span class="hljs-params">(ValidationParameter parameter)</span></span>; |
| } |
| </code></pre> |
| <h5 id="参数验证示例">参数验证示例</h5> |
| <pre><code class="lang-java"><span class="hljs-keyword">import</span> javax.validation.constraints.Min; |
| <span class="hljs-keyword">import</span> javax.validation.constraints.NotNull; |
| |
| <span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">interface</span> <span class="hljs-title">ValidationService</span> </span>{ |
| |
| <span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">save</span><span class="hljs-params">(@NotNull ValidationParameter parameter)</span></span>; <span class="hljs-comment">// 验证参数不为空</span> |
| |
| <span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">delete</span><span class="hljs-params">(@Min(<span class="hljs-number">1</span>)</span> <span class="hljs-keyword">int</span> id)</span>; <span class="hljs-comment">// 直接对基本类型参数验证</span> |
| } |
| </code></pre> |
| <h5 id="在客户端验证参数">在客户端验证参数</h5> |
| <pre><code class="lang-xml"><span class="hljs-tag"><<span class="hljs-name">dubbo:reference</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"validationService"</span> <span class="hljs-attr">interface</span>=<span class="hljs-string">"com.alibaba.dubbo.examples.validation.api.ValidationService"</span> <span class="hljs-attr">validation</span>=<span class="hljs-string">"true"</span> /></span> |
| </code></pre> |
| <h5 id="在服务器端验证参数">在服务器端验证参数</h5> |
| <pre><code class="lang-xml"><span class="hljs-tag"><<span class="hljs-name">dubbo:service</span> <span class="hljs-attr">interface</span>=<span class="hljs-string">"com.alibaba.dubbo.examples.validation.api.ValidationService"</span> <span class="hljs-attr">ref</span>=<span class="hljs-string">"validationService"</span> <span class="hljs-attr">validation</span>=<span class="hljs-string">"true"</span> /></span> |
| </code></pre> |
| <h5 id="验证异常信息">验证异常信息</h5> |
| <pre><code class="lang-java"><span class="hljs-keyword">import</span> javax.validation.ConstraintViolationException; |
| <span class="hljs-keyword">import</span> javax.validation.ConstraintViolationException; |
| |
| <span class="hljs-keyword">import</span> org.springframework.context.support.ClassPathXmlApplicationContext; |
| |
| <span class="hljs-keyword">import</span> com.alibaba.dubbo.examples.validation.api.ValidationParameter; |
| <span class="hljs-keyword">import</span> com.alibaba.dubbo.examples.validation.api.ValidationService; |
| <span class="hljs-keyword">import</span> com.alibaba.dubbo.rpc.RpcException; |
| |
| <span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">ValidationConsumer</span> </span>{ |
| |
| <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">main</span><span class="hljs-params">(String[] args)</span> <span class="hljs-keyword">throws</span> Exception </span>{ |
| String config = ValidationConsumer.class.getPackage().getName().replace(<span class="hljs-string">'.'</span>, <span class="hljs-string">'/'</span>) + <span class="hljs-string">"/validation-consumer.xml"</span>; |
| ClassPathXmlApplicationContext context = <span class="hljs-keyword">new</span> ClassPathXmlApplicationContext(config); |
| context.start(); |
| ValidationService validationService = (ValidationService)context.getBean(<span class="hljs-string">"validationService"</span>); |
| <span class="hljs-comment">// Error</span> |
| <span class="hljs-keyword">try</span> { |
| parameter = <span class="hljs-keyword">new</span> ValidationParameter(); |
| validationService.save(parameter); |
| System.out.println(<span class="hljs-string">"Validation ERROR"</span>); |
| } <span class="hljs-keyword">catch</span> (RpcException e) { <span class="hljs-comment">// 抛出的是RpcException</span> |
| ConstraintViolationException ve = (ConstraintViolationException) e.getCause(); <span class="hljs-comment">// 里面嵌了一个ConstraintViolationException</span> |
| Set<ConstraintViolation<?>> violations = ve.getConstraintViolations(); <span class="hljs-comment">// 可以拿到一个验证错误详细信息的集合</span> |
| System.out.println(violations); |
| } |
| } |
| } |
| </code></pre> |
| <h5 id="需要加入依赖">需要加入依赖</h5> |
| <pre><code class="lang-xml"><span class="hljs-tag"><<span class="hljs-name">dependency</span>></span> |
| <span class="hljs-tag"><<span class="hljs-name">groupId</span>></span>javax.validation<span class="hljs-tag"></<span class="hljs-name">groupId</span>></span> |
| <span class="hljs-tag"><<span class="hljs-name">artifactId</span>></span>validation-api<span class="hljs-tag"></<span class="hljs-name">artifactId</span>></span> |
| <span class="hljs-tag"><<span class="hljs-name">version</span>></span>1.0.0.GA<span class="hljs-tag"></<span class="hljs-name">version</span>></span> |
| <span class="hljs-tag"></<span class="hljs-name">dependency</span>></span> |
| <span class="hljs-tag"><<span class="hljs-name">dependency</span>></span> |
| <span class="hljs-tag"><<span class="hljs-name">groupId</span>></span>org.hibernate<span class="hljs-tag"></<span class="hljs-name">groupId</span>></span> |
| <span class="hljs-tag"><<span class="hljs-name">artifactId</span>></span>hibernate-validator<span class="hljs-tag"></<span class="hljs-name">artifactId</span>></span> |
| <span class="hljs-tag"><<span class="hljs-name">version</span>></span>4.2.0.Final<span class="hljs-tag"></<span class="hljs-name">version</span>></span> |
| <span class="hljs-tag"></<span class="hljs-name">dependency</span>></span> |
| </code></pre> |
| |
| |
| </section> |
| |
| </div> |
| <div class="search-results"> |
| <div class="has-results"> |
| |
| <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1> |
| <ul class="search-results-list"></ul> |
| |
| </div> |
| <div class="no-results"> |
| |
| <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1> |
| |
| </div> |
| </div> |
| </div> |
| |
| </div> |
| </div> |
| |
| </div> |
| |
| |
| |
| <a href="分组聚合.html" class="navigation navigation-prev " aria-label="Previous page: 4.14 分组聚合"> |
| <i class="fa fa-angle-left"></i> |
| </a> |
| |
| |
| <a href="结果缓存.html" class="navigation navigation-next " aria-label="Next page: 4.16 结果缓存"> |
| <i class="fa fa-angle-right"></i> |
| </a> |
| |
| |
| |
| </div> |
| |
| <script> |
| var gitbook = gitbook || []; |
| gitbook.push(function() { |
| gitbook.page.hasChanged({"page":{"title":"4.15 参数验证","level":"1.5.14","depth":2,"next":{"title":"4.16 结果缓存","level":"1.5.15","depth":2,"path":"demos/结果缓存.md","ref":"demos/结果缓存.md","articles":[]},"previous":{"title":"4.14 分组聚合","level":"1.5.13","depth":2,"path":"demos/分组聚合.md","ref":"demos/分组聚合.md","articles":[]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":[],"pluginsConfig":{"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"demos/参数验证.md","mtime":"2017-07-28T06:05:28.000Z","type":"markdown"},"gitbook":{"version":"3.2.2","time":"2017-07-28T06:06:18.782Z"},"basePath":"..","book":{"language":""}}); |
| }); |
| </script> |
| </div> |
| |
| |
| <script src="../gitbook/gitbook.js"></script> |
| <script src="../gitbook/theme.js"></script> |
| |
| |
| <script src="../gitbook/gitbook-plugin-search/search-engine.js"></script> |
| |
| |
| |
| <script src="../gitbook/gitbook-plugin-search/search.js"></script> |
| |
| |
| |
| <script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script> |
| |
| |
| |
| <script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script> |
| |
| |
| |
| <script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script> |
| |
| |
| |
| <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script> |
| |
| |
| |
| </body> |
| </html> |
| |