https://github.com/mygreen/splate
splate is Java Library for 2Way-SQL template
https://github.com/mygreen/splate
java springframework sql sqltemplate
Last synced: 3 months ago
JSON representation
splate is Java Library for 2Way-SQL template
- Host: GitHub
- URL: https://github.com/mygreen/splate
- Owner: mygreen
- License: apache-2.0
- Created: 2020-07-19T03:56:33.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2024-02-02T22:28:47.000Z (about 2 years ago)
- Last Synced: 2025-07-14T11:52:00.683Z (9 months ago)
- Topics: java, springframework, sql, sqltemplate
- Language: Java
- Homepage:
- Size: 1.89 MB
- Stars: 4
- Watchers: 2
- Forks: 1
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://maven-badges.herokuapp.com/maven-central/com.github.mygreen/splate/)
[](https://javadoc.io/doc/com.github.mygreen/splate)
[](https://github.com/mygreen/splate/actions/workflows/maven.yml)
[](https://sonarcloud.io/dashboard?id=com.github.mygreen%3Asplate)
# splate

splate(エス・プレート)は、 **2Way-SQL** 機能のみを [S2JDBC](http://s2container.seasar.org/2.4/ja/s2jdbc.html) から分離し、使いやすくしたライブラリです。
このライブラリは、SpringFrameworkに依存しています。理由は以下の通りです。
- SpringFrameworkに依存している理由として、普段、Javaで開発するときには、多くがSpringBootを利用しいる状況にあるためです。
- そのため、無理にSpringFrameworkに依存しないように作ってもコード量が増えるだけで、あまりメリットがないと考えられます。
- SpringFrameworkに依存しないで2Way-SQLを利用するならば、他の多くのライブラリ( [Doma2](https://doma.readthedocs.io/) / [DBFlute](http://dbflute.seasar.org/) / [Mirage-SQL](https://github.com/mirage-sql/mirage) / [uroboroSQL](https://future-architect.github.io/uroborosql-doc/) )が既に存在するので、そちらを利用することを検討した方がよいかもしれません。
## Licensee
Apache2 License
## Dependency
- Java 11+
- SpringFramework 5.0+
- Slf4j 1.7+
## Setup
Add dependency. ex) pom.xml
```xml
com.github.mygreen
splate
0.3
```
## How to use
1. Define SQL file.
```sql
select * from employee
/*BEGIN*/
where
/*IF salaryMin != null*/
salary >= /*salaryMin*/1000
/*END*/
/*IF salaryMax != null*/
and salary <= /*salaryMax*/2000
/*END*/
/*END*/
```
2. Create instance the ``SqlTemplateEngine`` and parse SQL template file.
```java
SqlTemplateEngine templateEngine = new SqlTemplateEngine();
SqlTemplate template = templateEngine.getTemplate("classpath:/sql/employee_select.sql");
```
3. Create template parameter with ``SqlTemplateContext``.
```java
public class SelectParam {
public BigDecimal salaryMin;
public BigDecimal salaryMax;
}
```
```java
// create parameter with JavaBean.
SelectParam param = new SelectParam();
param.salaryMin = new BigDecimal(1200);
param.salaryMax = new BigDecimal(1800);
// create instance of SqlTemplateContext.
SqlTemplateContext templateContext = new BeanPropertySqlTemplateContext(param);
```
4. Evaluating SQL template.
```java
ProcessResult result = template.process(templateContext);
// sql : select * from employee salary >= ? and salary <= ?
String sql = result.getSql();
// bind parameters
List params = result.getParameters();
```
## Documentation
- Project information and manual.
- https://mygreen.github.io/splate/index.html
- JavaDoc
- https://mygreen.github.io/splate/apidocs/index.html