{"id":21993019,"url":"https://github.com/homeant/fluent-validator","last_synced_at":"2025-04-30T14:26:00.426Z","repository":{"id":50081119,"uuid":"161307350","full_name":"homeant/fluent-validator","owner":"homeant","description":"fluent-validator","archived":false,"fork":false,"pushed_at":"2021-06-04T21:56:24.000Z","size":94,"stargazers_count":4,"open_issues_count":1,"forks_count":1,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-04-30T14:25:54.115Z","etag":null,"topics":["fluentvalidation","springboot","validator"],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/homeant.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-12-11T09:10:50.000Z","updated_at":"2021-11-11T16:21:25.000Z","dependencies_parsed_at":"2022-09-26T22:30:38.335Z","dependency_job_id":null,"html_url":"https://github.com/homeant/fluent-validator","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/homeant%2Ffluent-validator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/homeant%2Ffluent-validator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/homeant%2Ffluent-validator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/homeant%2Ffluent-validator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/homeant","download_url":"https://codeload.github.com/homeant/fluent-validator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251720978,"owners_count":21632749,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["fluentvalidation","springboot","validator"],"created_at":"2024-11-29T20:15:50.161Z","updated_at":"2025-04-30T14:26:00.400Z","avatar_url":"https://github.com/homeant.png","language":"Java","readme":"# fluent-validator\n\n\u003e 针对hibernate-validator 进行增强，站在巨人的肩膀上，让程序员对数据校验更加得心应手\n\n\n使用请仔细阅读官方文档：[fluent-validator](http://neoremind.com/2016/02/java%E7%9A%84%E4%B8%9A%E5%8A%A1%E9%80%BB%E8%BE%91%E9%AA%8C%E8%AF%81%E6%A1%86%E6%9E%B6fluent-validator/)\n\n## use\n\n```xml\n\u003cdependency\u003e\n\t\u003cgroupId\u003ecom.github.homeant\u003c/groupId\u003e\n\t\u003cartifactId\u003espring-boot-starter-fluent-validator\u003c/artifactId\u003e\n\t\u003cversion\u003e1.0.0.M1\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\n```java\n//此处FluentValid注解\npublic User install(@FluentValid(UserValidator.class) User user){\n\t...\n}\n```\n\n## spring bean\n\n上述** @FluentValid(UserValidator.class) **中的**UserValidator.class**交给spring进行管理\n```\nComponent\npubcli class UserValidator extends Validator{\n\t\n}\n```\n\n## config\n\n```yaml\nvalidator:\n  enable: true ## default true\n```\n\n\n## i18n\n\n```java\n@Bean\npublic IMessageService messageService() {\n\treturn new IMessageService() {\n\t\t//jdbc or rpc\n\t\t@Override\n\t\tpublic List\u003cMessageResource\u003e getAllMessage(Object... args) {\n\t\t\treturn null;\n\t\t}\n\t};\n}\n```\n\n## use of controller \n\n当前版本如果对controller 进行处理需要自己定义**@RestControllerAdvice**,，异常类为**com.github.homeant.validator.core.exception.ValidateFailException**\n\n```java\n@RestControllerAdvice\npublic class ExceptionHandle {\n\t@ExceptionHandler(value = ValidateFailException.class)\n    public ResponseEntity\u003cObject\u003e Handle(ValidateFailException exception){\n\t\tList\u003cMap\u003cString, String\u003e\u003e fields = new ArrayList\u003c\u003e();\n\t\tif(null!=exception.getErrors() \u0026\u0026 exception.getErrors().size()\u003e0) {\n\t\t\tfor (int i = 0; i \u003c exception.getErrors().size(); i++) {\n\t\t\t\tValidationError r = exception.getErrors().get(i);\n\t\t\t\tMap\u003cString, String\u003e field = new HashMap\u003c\u003e();\n\t\t\t\tfield.put(\"field\",r.getField());\n\t\t\t\tfield.put(\"errorMsg\",r.getErrorMsg());\n\t\t\t\tfields.add(field);\n\t\t\t}\n\t\t}\n\t\tmap.put(\"message\",exception.getMessage());\n\t\tmap.put(\"state\",416);\n\t\tmap.put(\"fields\", fields);\n\t\treturn ResponseEntity.status(416).body(map);\n    }\n}\n```\n\n## use of service\n\n在非controller中使用，请自行捕获异常，并处理\ndevelop\n\n\n## 版本计划\n\ncontroller 层校验,将错误信息装载到**org.springframework.validation.BindingResult**中，和spring validator 使用方式统一\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhomeant%2Ffluent-validator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhomeant%2Ffluent-validator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhomeant%2Ffluent-validator/lists"}