zealot-spring-boot-starter

Starter for using Zealot in Spring Boot generated dynamically SQL

License

License

Categories

Categories

Spring Boot Container Microservices
GroupId

GroupId

com.blinkfox
ArtifactId

ArtifactId

zealot-spring-boot-starter
Last Version

Last Version

1.0.0
Release Date

Release Date

Type

Type

jar
Description

Description

zealot-spring-boot-starter
Starter for using Zealot in Spring Boot generated dynamically SQL
Project URL

Project URL

https://github.com/blinkfox/zealot-spring-boot-starter
Source Code Management

Source Code Management

https://github.com/blinkfox/zealot-spring-boot-starter

Download zealot-spring-boot-starter

How to add to project

<!-- https://jarcasting.com/artifacts/com.blinkfox/zealot-spring-boot-starter/ -->
<dependency>
    <groupId>com.blinkfox</groupId>
    <artifactId>zealot-spring-boot-starter</artifactId>
    <version>1.0.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.blinkfox/zealot-spring-boot-starter/
implementation 'com.blinkfox:zealot-spring-boot-starter:1.0.0'
// https://jarcasting.com/artifacts/com.blinkfox/zealot-spring-boot-starter/
implementation ("com.blinkfox:zealot-spring-boot-starter:1.0.0")
'com.blinkfox:zealot-spring-boot-starter:jar:1.0.0'
<dependency org="com.blinkfox" name="zealot-spring-boot-starter" rev="1.0.0">
  <artifact name="zealot-spring-boot-starter" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.blinkfox', module='zealot-spring-boot-starter', version='1.0.0')
)
libraryDependencies += "com.blinkfox" % "zealot-spring-boot-starter" % "1.0.0"
[com.blinkfox/zealot-spring-boot-starter "1.0.0"]

Dependencies

compile (3)

Group / Artifact Type Version
com.blinkfox : zealot jar 1.3.1
org.springframework.boot : spring-boot-autoconfigure jar 2.0.1.RELEASE
org.springframework.boot : spring-boot-configuration-processor Optional jar 2.0.1.RELEASE

test (1)

Group / Artifact Type Version
org.springframework.boot : spring-boot-starter-test jar 2.0.1.RELEASE

Project Modules

There are no modules declared in this project.

zealot-spring-boot-starter

Build Status Javadocs HitCount GitHub issues GitHub license Maven Central GitHub forks GitHub stars codecov

Zealot是一个简单、强大的Java动态SQL和参数生成工具库。Zealot文档地址

zealot-spring-boot-starter则是Zealot在SpringBoot中使用的快速集成版,默认不需要任何配置即可使用。

获取Zealot Spring Boot Starter

<dependency>
    <groupId>com.blinkfox</groupId>
    <artifactId>zealot-spring-boot-starter</artifactId>
</dependency>

: 适用于SpringBoot2的项目,JDK1.8及以上。

核心配置

在 Spring Boot 中使用Maven集成了zealot-spring-boot-starter之后,默认不需要任何配置,Zealot就可以开始工作了,以下是在application.properties文件中Zealot的默认配置和说明,供参考配置:

# 是否开启调试模式,如果开启的话,每次调用都会实时从最新的xml文件中获取sql,默认值为false.
zealot.debug=false

# 是否打印zealot的启动banner,默认为true.
zealot.print-banner=true

# 是否打印zealot的sql日志,默认为true.
zealot.print-sql=true

# zealot的XML文件所在的位置,多个用逗号隔开,可以是目录也可以是具体的xml文件,默认是名为'zealot'的资源目录及子目录下的位置.
# 所以,如果不配置其他目录,你的xml就应该存放在这样的目录和子目录下:'main/resources/zealot/',才能被扫描到,其他目录的则需要更改此配置项
zealot.xml-locations=zealot

# zealot的自定义handler处理器所在的位置,多个用逗号隔开,可以是目录也可以是具体的java或class文件路径,默认为空,以下是参考示例.
# 如果你有自定义标签的话,则只需在该标签对应的Handler上使用'@Tagger'和'@Taggers'注解即可配置标签了.
#zealot.handler-locations=com.blinkfox.zealotboot.handler

简单示例

Zealot的详细使用可参考这里的文档,以下只是最简单的示例展示。

Zealot的使用

首先,在resouces资源目录下,新建zealot目录,然后在zealot目录中新建student.xml的zealot xml文件,内容如下:

<?xml version="1.0" encoding="UTF-8"?>
<!-- 查询老师相关的SQL信息,命名空间nameSpace为zealots的根节点属性,各xml文件的nameSpace不能相同. -->
<zealots nameSpace="myTeacher">

    <!-- 根据Id查询学生信息. -->
    <zealot id="queryTeacherById">
        SELECT * FROM t_teacher AS t WHERE
        <equal field="t.c_id" value="id"/>
    </zealot>

</zealots>

接下来是在单元测试的Java代码中调用,代码如下:

/**
 * 测试从zealot/teacher.xml中调用生成动态SQL.
 */
@Test
public void testQueryueryTeacherById() {
    SqlInfo sqlInfo = Zealot.getSqlInfo("myTeacher", "queryTeacherById",
            ParamWrapper.newInstance("id", "123").toMap());
    String expectedSql = "SELECT * FROM t_teacher AS t WHERE t.c_id = ?";

    Assert.assertEquals(expectedSql, sqlInfo.getSql());
    Assert.assertArrayEquals(new Object[]{"123"}, sqlInfo.getParamsArr());
}

许可证

zealot-spring-boot-starter类库遵守[Apache License 2.0][6] 许可证。

版本更新记录

  • v1.0.0(2018-05-03)
    • 新增zealot的默认快速集成和单元测试

Versions

Version
1.0.0