Version v0.24 of the documentation is no longer actively maintained. The site that you are currently viewing is an archived snapshot. For up-to-date documentation, see the latest version.

Examples

Here are some examples.

Overview

We have the following examples:

  • Console applications
  • Spring Boot web applications
  • Code generation from databases

Prerequisites

  • JDK 8 or later

Clone

To run locally, clone the komapper/komapper-examples repository:

$ git clone https://github.com/komapper/komapper-examples.git
$ cd komapper-examples

Try it out!

Console applications

Execute the following command to run the JDBC version:

$ ./gradlew :console-jdbc:run

Execute the following command to run the R2DBC version:

$ ./gradlew :console-r2dbc:run

Spring Boot web applications

Execute the following command to run the JDBC version:

$ ./gradlew :spring-boot-jdbc:bootRun

Execute the following command to run the R2DBC version:

$ ./gradlew :spring-boot-r2dbc:bootRun

Once the application starts, open the following URL: http://localhost:8080

To add data, use the text parameter as follows: http://localhost:8080/?text=Hi

When you open the following URL http://localhost:8080 again, the added data will be shown.

Code generation from databases

We provide the gradle plugin that generates code from database schemas.

Execute the following command to generate code from MySQL:

$ ./gradlew :codegen:komapperMysqlGenerator

Execute the following command to generate code from PostgreSQL:

$ ./gradlew :codegen:komapperPostgresqlGenerator

Execute the following command to generate code from both MySQL and PostgreSQL:

$ ./gradlew :codegen:komapperGenerator

Make sure the source code is generated under the codgen/src/main/kotlin directory.

Last modified August 15, 2021: Add heading IDs (5798dd3)