Create a Project
Create a Spring Boot Project
Use https://start.spring.io/ to create a Spring Boot project. You need to choose your preferred language - Java or Kotlin.
The choice of language is important because Jimmer supports two different sets of APIs.
-
Java API - Ensures maximum developer usage
-
Kotlin API - APIs designed specifically for Kotlin to optimize the development experience
Add Dependencies
Jimmer itself is highly neutral and can be used without Spring Boot. But it also provides great integration with Spring Boot.
Users can choose to use it with or without Spring Boot. Different choices require adding different dependencies.
-
groupId: org.babyfish.jimmer
-
artifactId:
Integrate with Spring Boot Standalone Usage Java jimmer-spring-boot-starter jimmer-sql Kotlin jimmer-sql-kotlin
Compared to standalone usage, integrating with Spring Boot is simpler. So this tutorial will demonstrate the jimmer-spring-boot-starter
.
Modify build.gradle or pom.xml to add dependencies:
- Maven
- Gradle
- Gradle (Kts)
<properties>
<jimmer.version>0.9.37</jimmer.version>
</properties>
<dependencies>
<dependency>
<groupId>org.babyfish.jimmer</groupId>
<artifactId>jimmer-spring-boot-starter</artifactId>
<version>${jimmer.version}</version>
</dependency>
...other dependencies omitted...
</dependencies>
ext {
jimmerVersion = '0.9.37'
}
dependencies {
implementation "org.babyfish.jimmer:jimmer-spring-boot-starter:${jimmerVersion}"
...other dependencies omitted...
}
val jimmerVersion = "0.9.37"
dependencies {
implementation("org.babyfish.jimmer:jimmer-spring-boot-starter:${jimmerVersion}")
...other dependencies omitted...
}
As a step-by-step example, we only demonstrate Jimmer's standard build method here.
The community also provides gradle plugins, please refer to APT/KSP
Additional Configuration Needed for Kotlin
If using Kotlin, you must modify the Spring Boot configuration file - this is very important.
Kotlin projects must configure jimmer.language
- application.properties
- application.yml
jimmer.language = kotlin
jimmer:
language: kotlin
Other Useful Configurations
In addition to the required jimmer.language
for Kotlin projects, there are other useful configurations.
Here are a few basic configurations that work for both Java and Kotlin:
Property | Type | Default | Description |
---|---|---|---|
jimmer.dialect | string | org.babyfish.jimmer.sql.dialect.DefaultDialect | Database dialect class name |
jimmer.show-sql | boolean | false | Print executed SQL if true |
jimmer.pretty-sql | boolean | false | Ensure that the printed SQL is well-formatted (compact by default) |
jimmer.database-validation-mode | NONE|WARNING|ERROR | NONE | Validate consistency between database schema and entity types. WARNING logs inconsistencies, ERROR throws errors. |
See Spring/Appendix for complete documentation on configurations.
- application.properties
- application.yml
jimmer.dialect = org.babyfish.jimmer.sql.dialect.MySqlDialect
jimmer.show-sql = true
jimmer.pretty-sql = true
jimmer.database-validation-mode = ERROR
...other configurations omitted...
jimmer:
dialect: org.babyfish.jimmer.sql.dialect.MySqlDialect
show-sql: true
pretty-sql: true
database-validation-mode: ERROR
...other configurations omitted...
Add Other Required Dependencies
In addition to Jimmer, some other dependencies are required like spring-web, JDBC driver, etc.
Modify build.gradle or pom.xml to add dependencies:
- Maven
- Gradle
- Gradle (Kts)
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.30</version>
<scope>runtime</scope>
</dependency>
...other dependencies omitted...
</dependencies>
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
runtimeOnly 'mysql:mysql-connector-java:8.0.30'
...other dependencies omitted...
}
dependencies {
implementation("org.springframework.boot:spring-boot-starter-web")
runtimeOnly("mysql:mysql-connector-java:8.0.30")
...other dependencies omitted...
}