{"id":15196882,"url":"https://github.com/joutvhu/spring-dynamic-velocity","last_synced_at":"2026-03-06T10:31:46.676Z","repository":{"id":65507745,"uuid":"581288116","full_name":"joutvhu/spring-dynamic-velocity","owner":"joutvhu","description":"Velocity dynamic query template provider.","archived":false,"fork":false,"pushed_at":"2023-07-28T07:02:38.000Z","size":152,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-02T09:17:15.702Z","etag":null,"topics":["dynamic-query","query-template","spring","velocity"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/joutvhu.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-12-22T19:16:56.000Z","updated_at":"2023-01-07T21:58:01.000Z","dependencies_parsed_at":"2024-09-18T22:05:17.165Z","dependency_job_id":null,"html_url":"https://github.com/joutvhu/spring-dynamic-velocity","commit_stats":{"total_commits":15,"total_committers":2,"mean_commits":7.5,"dds":"0.19999999999999996","last_synced_commit":"8f326e325380ae90812648b81c9bca315d48d426"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/joutvhu/spring-dynamic-velocity","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joutvhu%2Fspring-dynamic-velocity","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joutvhu%2Fspring-dynamic-velocity/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joutvhu%2Fspring-dynamic-velocity/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joutvhu%2Fspring-dynamic-velocity/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/joutvhu","download_url":"https://codeload.github.com/joutvhu/spring-dynamic-velocity/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joutvhu%2Fspring-dynamic-velocity/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30171869,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-06T07:56:45.623Z","status":"ssl_error","status_checked_at":"2026-03-06T07:55:55.621Z","response_time":250,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: 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":["dynamic-query","query-template","spring","velocity"],"created_at":"2024-09-28T00:05:35.952Z","updated_at":"2026-03-06T10:31:46.626Z","avatar_url":"https://github.com/joutvhu.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Spring Dynamic Velocity\n\nA [Dynamic Query Template Provider](https://github.com/joutvhu/spring-dynamic-commons#dynamic-query-template-provider) base on [Apache Velocity](https://velocity.apache.org) template engine.\n\nYou can refer to [Velocity Document](https://velocity.apache.org/engine/devel/user-guide.html) to know more about rules.\n\n## Using\n\nYou need to configure a VelocityQueryTemplateProvider bean to use this template provider.\n\n```java\n@Bean\npublic DynamicQueryTemplateProvider dynamicQueryTemplateProvider() {\n    VelocityQueryTemplateProvider provider = new VelocityQueryTemplateProvider();\n    provider.setEncoding(\"UTF-8\");\n    provider.setTemplateLocation(\"classpath:/query\");\n    provider.setSuffix(\".dsql\");\n    return provider;\n}\n```\n\nThe VelocityQueryTemplateProvider has the following parameters:\n\n- `setTemplateLocation`: in case you do not specify the query template on the `@DynamicQuery` annotation, the provider will find it from external template files. The TemplateLocation Is location you put the external template files, default is `classpath:/query`\n- `setSuffix`: is the suffix of the external template files, default is `.dsql`. If you don't want the provider to load external templates then set this value to `null`.\n- `setEncoding`: is the encoding of templates, default is `UTF-8`\n- `setConfiguration`: is a VelocityTemplateConfiguration, used to customize Velocity configuration.\n\nEach template in external template file will start with a template name definition line. The template name definition line must be start with two dash characters (`--`).\n\n## Directives\n\n### Where Directive\n\n`#where` directive knows to only insert `WHERE` if there is any content returned by the containing tags. Furthermore, if that content begins or ends with `AND` or `OR`, it knows to strip it off.\n\n```sql\nselect t from User t\n#where\n  #if($firstName != $null)\n    and t.firstName = :firstName\n  #end\n  #if($lastName != $null)\n    and t.lastName = :lastName\n  #end\n#end\n```\n\n### Set Directive\n\n`#set` directive is like the `#where` directive, it removes the commas if it appears at the begins or ends of the content. Also, it will insert `SET` if the content is not empty.\n\n```sql\nupdate User t\n#set\n  #if($firstName != $null)\n    t.firstName = :firstName,\n  #end\n  #if($lastName != $null)\n    t.lastName = :lastName,\n  #end\n#end\nwhere t.userId = :userId\n```\n\nNote to avoid confusion with [the #set directive used for setting the value of a reference](https://velocity.apache.org/engine/devel/user-guide.html#set).\nThis `#set` directive is a block of `#set` _(without parameters)_ and `#end`.\n\n### Trim Directive\n\n`#trim` directive has four parameters: `prefix`, `prefixOverrides`, `suffix`, `suffixOverrides`.\n\n- `prefix` _(first parameter)_ is the string value that will be inserted at the start of the content if it is not empty, value type is string.\n- `prefixOverrides` _(second parameter)_ are values that will be removed if they are at the start of a content, value type is list of strings.\n- `suffix` _(third parameter)_ is the string value that will be inserted at the end of the content if it is not empty, value type is string.\n- `suffixOverrides` _(fourth parameter)_ are values that will be removed if they are at the end of a content, value type is list of strings.\n\n ```sql\n#trim(\"where (\", [\"and \", \"or \"], \")\", [\" and\", \" or\"])\n  #if($productName != $null)\n    t.productName = :productName or\n  #end\n  #if($category != $null)\n    t.category = :category or\n  #end\n#end\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoutvhu%2Fspring-dynamic-velocity","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjoutvhu%2Fspring-dynamic-velocity","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoutvhu%2Fspring-dynamic-velocity/lists"}