{"id":19032739,"url":"https://github.com/joutvhu/spring-dynamic-freemarker","last_synced_at":"2025-04-13T13:14:13.321Z","repository":{"id":65507746,"uuid":"579889816","full_name":"joutvhu/spring-dynamic-freemarker","owner":"joutvhu","description":"Freemarker dynamic query template provider.","archived":false,"fork":false,"pushed_at":"2023-07-28T06:57:04.000Z","size":152,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-13T13:13:52.264Z","etag":null,"topics":["dynamic-query","freemarker","query-template","spring"],"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-19T07:35:46.000Z","updated_at":"2024-09-11T06:24:15.000Z","dependencies_parsed_at":"2024-11-08T21:31:13.175Z","dependency_job_id":null,"html_url":"https://github.com/joutvhu/spring-dynamic-freemarker","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joutvhu%2Fspring-dynamic-freemarker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joutvhu%2Fspring-dynamic-freemarker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joutvhu%2Fspring-dynamic-freemarker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joutvhu%2Fspring-dynamic-freemarker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/joutvhu","download_url":"https://codeload.github.com/joutvhu/spring-dynamic-freemarker/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248717237,"owners_count":21150389,"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":["dynamic-query","freemarker","query-template","spring"],"created_at":"2024-11-08T21:30:46.295Z","updated_at":"2025-04-13T13:14:13.296Z","avatar_url":"https://github.com/joutvhu.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Spring Dynamic Freemarker\n\nA [Dynamic Query Template Provider](https://github.com/joutvhu/spring-dynamic-commons#dynamic-query-template-provider) base on [Apache FreeMarker](https://freemarker.apache.org) template engine.\n\nYou can refer to [Freemarker Document](https://freemarker.apache.org/docs/index.html) to know more about rules.\nUse [Online FreeMarker Template Tester](https://try.freemarker.apache.org) with `tagSyntax = angleBracket` and `interpolationSyntax = dollar` to test your query template.\n\n## Using\n\nYou need to configure a FreemarkerQueryTemplateProvider bean to use this template provider.\n\n```java\n@Bean\npublic DynamicQueryTemplateProvider dynamicQueryTemplateProvider() {\n    FreemarkerQueryTemplateProvider provider = new FreemarkerQueryTemplateProvider();\n    provider.setEncoding(\"UTF-8\");\n    provider.setTemplateLocation(\"classpath:/query\");\n    provider.setSuffix(\".dsql\");\n    return provider;\n}\n```\n\nThe FreemarkerQueryTemplateProvider 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 FreemarkerTemplateConfiguration, used to customize Freemarker 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\u003c@where\u003e\n  \u003c#if firstName?has_content\u003e\n    and t.firstName = :firstName\n  \u003c/#if\u003e\n  \u003c#if lastName?has_content\u003e\n    and t.lastName = :lastName\n  \u003c/#if\u003e\n\u003c/@where\u003e\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\u003c@set\u003e\n  \u003c#if firstName?has_content\u003e\n    t.firstName = :firstName,\n  \u003c/#if\u003e\n  \u003c#if lastName?has_content\u003e\n    t.lastName = :lastName,\n  \u003c/#if\u003e\n\u003c/@set\u003e\nwhere t.userId = :userId\n```\n\n### Trim Directive\n\n`@trim` directive has four parameters: `prefix`, `prefixOverrides`, `suffix`, `suffixOverrides`.\n\n- `prefix` 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` are values that will be removed if they are at the start of a content, value type is list of strings.\n- `suffix` 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` 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\u003c@trim prefix=\"where (\" prefixOverrides=[\"and \", \"or \"] suffix=\")\" suffixOverrides=[\" and\", \" or\"]\u003e\n  \u003c#if productName?has_content\u003e\n    t.productName = :productName or\n  \u003c/#if\u003e\n  \u003c#if category?has_content\u003e\n    t.category = :category or\n  \u003c/#if\u003e\n\u003c/@trim\u003e\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoutvhu%2Fspring-dynamic-freemarker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjoutvhu%2Fspring-dynamic-freemarker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoutvhu%2Fspring-dynamic-freemarker/lists"}