{"id":40405117,"url":"https://github.com/tianyirenjian/jvalidation","last_synced_at":"2026-01-20T13:38:19.077Z","repository":{"id":57729077,"uuid":"428535008","full_name":"tianyirenjian/jvalidation","owner":"tianyirenjian","description":"A spring boot validation library from laravel.","archived":false,"fork":false,"pushed_at":"2023-09-06T03:04:28.000Z","size":149,"stargazers_count":12,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-08-11T22:41:19.550Z","etag":null,"topics":["java","validate","validation","validation-library","validator"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tianyirenjian.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-11-16T05:57:01.000Z","updated_at":"2024-10-14T13:49:06.000Z","dependencies_parsed_at":"2022-09-10T23:41:32.117Z","dependency_job_id":null,"html_url":"https://github.com/tianyirenjian/jvalidation","commit_stats":null,"previous_names":[],"tags_count":20,"template":false,"template_full_name":null,"purl":"pkg:github/tianyirenjian/jvalidation","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tianyirenjian%2Fjvalidation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tianyirenjian%2Fjvalidation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tianyirenjian%2Fjvalidation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tianyirenjian%2Fjvalidation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tianyirenjian","download_url":"https://codeload.github.com/tianyirenjian/jvalidation/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tianyirenjian%2Fjvalidation/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28603891,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-20T12:01:53.233Z","status":"ssl_error","status_checked_at":"2026-01-20T12:01:46.545Z","response_time":117,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["java","validate","validation","validation-library","validator"],"created_at":"2026-01-20T13:38:18.999Z","updated_at":"2026-01-20T13:38:19.067Z","avatar_url":"https://github.com/tianyirenjian.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"JValidation\n=======\n\n[![License](https://img.shields.io/badge/license-apache2.0-green.svg)](https://github.com/tianyirenjian/jvalidation/blob/master/LICENSE)\n[![Maven Central](https://img.shields.io/maven-central/v/com.tianyisoft.jvalidate/jvalidation.svg?label=Maven%20Central)](https://search.maven.org/search?q=g:%22com.tianyisoft.jvalidate%22%20AND%20a:%22jvalidation%22)\n\nEnglish | [中文版](./README.zh-CN.md)\n\n\u003cb\u003e This library only works with spring boot 2.x version. \u003c/b\u003e\n\nJValidation is a validation library developed for spring boot. There are a variety of built-in validators, mainly referring to the validators of the Laravel framework. Currently available validation classes are being added. Compared to most validators, the biggest advantage is that it supports database validation.\n\ninstallation\n---------------\n\n````xml\n\u003cdependency\u003e\n  \u003cgroupId\u003ecom.tianyisoft.jvalidate\u003c/groupId\u003e\n  \u003cartifactId\u003ejvalidation\u003c/artifactId\u003e\n  \u003cversion\u003e1.6.1\u003c/version\u003e\n\u003c/dependency\u003e\n````\n\nHow to use\n----------------\n\n##### The first way\n\n1. Add the `@EnableJValidate` annotation to the SpringBootApplication.\n2. Add the `@Jvalidated` annotation to the method of the controller to be validated (no longer required after version 1.5.0)\n3. Add the `@Jvalidated` annotation to the parameters of the method of the controller to be validated to support grouping and setting data sources\n4. Then you can write various validation rules in the class to be validated\n\nThe following code:\n\n````java\n@JValidated // (no longer required after version 1.5.0)\n@PostMapping(\"/users\")\npublic User store(@RequestBody @JValidated User user) {\n    return user;\n}\n````\n\nThe above code will return a 422 error when validating an error. If you want to handle the error yourself, you can use a BindingErrors class to receive the error message:\n````java\n@PostMapping(\"/users\")\npublic User store(@RequestBody @JValidated(groups={xxx.class}) User user, BindingErrors bindingErrors) {\n    if (bindingErrors.hasErrors()) {\n        //...\n    }\n    return user;\n}\n````\n\n##### Second way\nIf you do not use annotations, static calls are also supported. Two methods are provided, which can return a map containing errors and handle them yourself:\n\n````java\ncom.tianyisoft.jvalidate.JValidator.validate(Object object, Class\u003c?\u003e[] groups)\ncom.tianyisoft.jvalidate.JValidator.validate(Object object, Class\u003c?\u003e[] groups, JdbcTemplate jdbcTemplate) // use database\ncom.tianyisoft.jvalidate.JValidator.validate(Object object, Class\u003c?\u003e[] groups, JdbcTemplate jdbcTemplate, String language, String defaultLang) // use i18n\n````\n\nStart validate\n-------------\n\nAdd validation rules to the User class to be validated, such as:\n\n````java\n\nimport com.tianyisoft.jvalidate.annotations.*;\nimport java.time.Instant;\nimport java.time.LocalDate;\nimport java.util.Date;\nimport java.util.List;\n\npublic class User {\n    @Bail // Do not continue to validate name when name validation fails for the first time. Does not affect other fields\n    @Required(message = \"%s should not be empty\") // Verify that it is not null, the string is not equal to the empty string, the length of the array or Collection object is greater than 0\n    @Alpha // only letters are allowed\n    @Between(min = 6, max = 10) // length is between 6 - 10\n    private String name;\n    @Required\n    @Url // is a valid url address\n    private String homepage;\n    @Required\n    @Email // is a valid email address\n    @Unique(table = \"users\", field = \"email\", groups = {Create.class}) // Verify that the database is not duplicated, at creation time\n    @Unique(table = \"users\", field = \"email\", groups = {Update.class}, where = \" and id != {{ request.path.id }} \") // Verify that the database is not duplicated, remove id is equal to the id of the path parameter of the request, which is used when modifying\n    @EndsWith(ends = {\"com\", \"cc\"}) // ends with com or cc\n    private String email;\n    @AfterOrEqual(date = \"1980-01-01\") // The date is greater than or equal to the specified date\n    @BeforeOrEqual(date = \"2013-12-31\") // The date is less than or equal to the specified date\n    private Date birthday;\n    @After(date = \"1980-01-01T00:00:00.000Z\") // The date is greater than or equal to the specified date, the field type is Instant\n    @AfterOrEqual(date = \"1980-01-01T00:00:00.000Z\") // The date is less than or equal to the specified date, the field type is Instant\n    private Instant birthday2;\n\n    @Between(min = 8, max = 70) // age is between 8 - 70\n    private Integer age;\n    @Min(0) // minimum value\n    @Max(100) // maximum value\n    private Long score;\n    @Distinct // no duplicate values allowed\n    @Between(min= 1, max= 2) // length limit\n    private List\u003cString\u003e hobbies;\n\n // getters and setters\n}\nclass Update{}\n````\n\nWhen validation fails, a 422 error will be returned, and the error details will be returned in the message body:\n\n````json\n{\n    \"message\": \"The given data was invalid.\",\n    \"errors\": {\n        \"birthday\": [\n            \"birthday must be a date greater than or equal to 1980-01-01\"\n        ],\n        \"score\": [\n            \"score cannot be greater than 100\"\n        ],\n        \"hobbies\": [\n            \"hobbies must be between 1 and 2\"\n        ],\n        \"name\": [\n            \"name can only consist of letters\"\n        ],\n        \"email\": [\n            \"email already exists in users\"\n        ],\n        \"age\": [\n            \"age must be between 8 and 70\"\n        ]\n    }\n}\n````\n\nThe return status code and error structure can also be customized, just create a bean named `validateFailedExceptionHandler`, and then you can catch `ValidateFailedException` to handle errors yourself.\n\n````java\n@Bean\npublic void validateFailedExceptionHandler() {}\n````\nWhen the parameter contains `BindingErrors` type, the error information will be put in it, and the 422 error will no longer be automatically returned. Usage is similar to `BindingResult`. Does not sometimes follow the wrong logic before.\n\n\n\nillustrate\n-----------------\n\nJValidation uses the default dataSource, other data sources may be used via `jvalidation.datasource-name`\n\nDecide whether to verify based on conditions\n-----------------\n\nAll validators can accept a Condition implementation class, use the needValidate method in the class to determine whether validation is required\n\nThe needValidate method of the Condition interface accepts Object[] parameters, which can be passed through the validator's params, and params can directly pass strings.\nYou can also pass {{ this }} to represent the current object, {{ xxx }} to represent other fields of the current object,\nOr use {{ request.path.id / request.get.id / request.header[s].id }} to get the information in the request\n\nExample:\n\n````java\nimport com.tianyisoft.jvalidate.annotations.Required;\n\npublic class User {\n    @Required(condition = NameCondition.class, params = {\"foo\", \"{{ this }}\", \"{{ bar }}\"})\n    private String name;\n    // getters and setters\n}\n\nclass NameCondition implements Condition {\n    @override\n    public Boolean needValidate(Object[] args) {\n        System.out.println(Arrays.toString(args)); // View the passed parameters\n        // Determine whether to verify according to the parameters\n        return true;\n    }\n}\n````\n\ni18n support\n------------\n\nThe i18n function has been supported since version 1.6. For the language file format, please refer to the files in the resources folder.\n\nYou can create a language file with the same name in the resources directory of the spring boot project to override the default language file.\n\nYou can also create new language files in the resources directory to supplement the system language files.\n\nThe default behavior is to use LocaleContextHolder.getLocale() to automatically determine the language to use. If the corresponding language file is not found, the default language is used. You can configure the default language using \"jvalidation.default-lang\", and if it's not configured, the default language will be English.\n\nAvailable Validation Rules\n-----------------\n\n##### Accepted\nMust be \"yes\" , \"on\" , \"1\" or \"true\"\n\n##### After\nMust be after the date of date, date can be a date value or other field names, when it is other fields, it needs to be of the same type\n\n##### AfterOrEqual\nMust be a date greater than or equal to date. date is used the same as After\n\n##### Alpha\nmust consist of letters\n\n##### AlphaDash\nCan only contain letters, numbers, dashes (-) and underscores (_)\n\n##### AlphaNum\nCan only consist of letters and numbers\n\n##### Bail\nWhen the first failure is encountered, the subsequent verification is stopped, only for the current field, and other fields will continue to be verified. For normal use, please put it in the first field of the field validator.\n\n##### Before\nOpposite of AfterOrEqual\n\n##### BeforeOrEqual\nOpposite of After\n\n##### Between\nWhen the field is a number, it means that the value is in the middle of the number, and when the field is a subclass of string, array or Collection, it means that the length of the field is between the maximum and minimum values\n\n##### DateEquals\nMust be a date equal to date\n\n##### Different\nMust have a different value from the specified field, you can choose to set `strict` to select strict mode, use `==` for strict mode comparison, otherwise use `equals` for comparison\n\n##### Distinct\nCan only be used for lists or arrays, where no duplicate values are required\n\n##### Email\nMust be an email address\n\n##### EndsWith\nThe string must end with one of the specified values\n\n##### Exists\nThe database must already exist, and database support is required.\n\nFor example: `@Exists(table = \"users\", field = \"email\", where = \" and id != {{id}} \")`\n\nOr: `@Exists(sql = \"select count(*) from users where email = ? and id = {{ request.path.user }}\")`\n\nIndicates that the email field in the users table must be equal to the current field value, and the where statement excludes those whose id is equal to the current object's id value.\n\nIn the where condition, you can use {{ request.path.id / request.get.id / request.header[s].id }} to get the information in the request, which is especially useful when modifying objects.\n\n##### In\nValidation string must be in the given value\n\n##### Ip\nMust be an ip address, either ipv4 or ipv6 is fine\n\n##### Ipv4\nMust be an ipv4 address\n\n##### Ipv6\nMust be an ipv6 address\n\n##### Max\nWhen the field is a number, it represents the maximum value, and when the field is a subclass of String, Array or Collection, it represents the maximum length\n\n##### Min\nWhen the field is a number, it means the minimum value, and when the field is a subclass of string, array or Collection, it means the minimum length\n\n##### NotRegexp\nmust not match the regular expression\n\n##### Regexp\nMust match regular expression\n\n##### Required\nCannot be null, when allowEmpty is false, the string cannot be empty, and the length of the array or Collection object cannot be 0\n\n##### RequiredIf\nObsolete, can be implemented directly using Required\n\n##### StartsWith\nString must start with one of several values specified\n\n##### Unique\nIt cannot be repeated in the database and requires database support.\n\nExample: `@Unique(table = \"users\", field = \"email\", where = \" and id != {{id}} \")`\n\nOr: `@Unique(sql = \"select count(*) from users where email = ? and id != {{ request.path.user }}\")`\n\nIndicates that the email field in the users table cannot be repeated, and the id equal to the id value of the current object is excluded through the where statement.\n\nIn the where condition, you can use {{ request.path.id / request.get.id / request.header[s].id }} to get the information in the request, which is especially useful when modifying objects.\n\n##### UniqueGroup\nUsed to combine multiple Unique\n\n##### Url\nField value must be a url address\n\nMore rules are being added...\n\nFunctions are being added, documents are being optimized...\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftianyirenjian%2Fjvalidation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftianyirenjian%2Fjvalidation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftianyirenjian%2Fjvalidation/lists"}