Skip to content

Commit 7e2dcaa

Browse files
committed
Update README.adoc for Kotlin
Signed-off-by: Danil Pavlov <danil.pavlov@jetbrains.com>
1 parent 6e34293 commit 7e2dcaa

File tree

1 file changed

+37
-16
lines changed

1 file changed

+37
-16
lines changed

README.adoc

Lines changed: 37 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ This guide walks you through the process of building an application that uses Sp
88

99
== What You Will Build
1010

11-
You will build an application that stores `Customer` POJOs (Plain Old Java Objects) in a memory-based database.
11+
You will build an application that stores `Customer` objects in a memory-based database.
1212

1313
== What You need
1414

@@ -19,33 +19,38 @@ include::https://raw.githubusercontent.com/spring-guides/getting-started-macros/
1919
[[scratch]]
2020
== Starting with Spring Initializr
2121

22-
You can use this https://start.spring.io/#!type=maven-project&language=java&platformVersion=3.1.5&packaging=jar&jvmVersion=17&groupId=com.example&artifactId=accessing-data-jpa&name=accessing-data-jpa&description=Demo%20project%20for%20Spring%20Boot&packageName=com.example.accessing-data-jpa&dependencies=data-jpa,h2[pre-initialized project] and click Generate to download a ZIP file. This project is configured to fit the examples in this tutorial.
22+
You can use this https://start.spring.io/#!type=maven-project&platformVersion=3.5.5&packaging=jar&jvmVersion=17&groupId=com.example&artifactId=accessing-data-jpa&name=accessing-data-jpa&description=Demo%20project%20for%20Spring%20Boot&packageName=com.example.accessingdatajpa&dependencies=data-jpa,h2[pre-initialized project] and click Generate to download a ZIP file. This project is configured to fit the examples in this tutorial.
2323

2424
To manually initialize the project:
2525

2626
. Navigate to https://start.spring.io.
2727
This service pulls in all the dependencies you need for an application and does most of the setup for you.
28-
. Choose either Gradle or Maven and the language you want to use. This guide assumes that you chose Java.
28+
. Choose either Gradle or Maven and the language you want to use.
2929
. Click *Dependencies* and select *Spring Data JPA* and then *H2 Database*.
3030
. Click *Generate*.
3131
. Download the resulting ZIP file, which is an archive of a web application that is configured with your choices.
3232

3333
NOTE: If your IDE has the Spring Initializr integration, you can complete this process from your IDE.
3434

35-
NOTE: You can also fork the project from Github and open it in your IDE or other editor.
35+
NOTE: You can also fork the project from GitHub and open it in your IDE or other editor.
3636

3737
[[initial]]
3838
== Define a Simple Entity
3939

4040
In this example, you store `Customer` objects, each annotated as a JPA entity. The
41-
following listing shows the Customer class (in
42-
`src/main/java/com/example/accessingdatajpa/Customer.java`):
41+
following listing shows the Customer class:
4342

4443
====
45-
[source,java,tabsize=2,indent=0]
44+
[source,java,indent=0,subs="verbatim,quotes",role="primary"]
45+
.Java
4646
----
4747
include::complete/src/main/java/com/example/accessingdatajpa/Customer.java[]
4848
----
49+
[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
50+
.Kotlin
51+
----
52+
include::complete-kotlin/src/main/kotlin/com/example/accessingdatajpa/Customer.kt[]
53+
----
4954
====
5055

5156
Here you have a `Customer` class with three attributes: `id`, `firstName`, and `lastName`.
@@ -64,7 +69,7 @@ that the ID should be generated automatically.
6469
The other two properties, `firstName` and `lastName`, are left unannotated. It is assumed
6570
that they are mapped to columns that share the same names as the properties themselves.
6671

67-
The convenient `toString()` method print outs the customer's properties.
72+
The convenient `toString()` method prints out the customer's properties.
6873

6974
== Create Simple Queries
7075

@@ -73,13 +78,19 @@ compelling feature is the ability to create repository implementations automatic
7378
runtime, from a repository interface.
7479

7580
To see how this works, create a repository interface that works with `Customer` entities
76-
as the following listing (in `src/main/java/com/example/accessingdatajpa/CustomerRepository.java`) shows:
81+
as the following listing shows:
7782

7883
====
79-
[source,java,tabsize=2]
84+
[source,java,indent=0,subs="verbatim,quotes",role="primary"]
85+
.Java
8086
----
8187
include::complete/src/main/java/com/example/accessingdatajpa/CustomerRepository.java[]
8288
----
89+
[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
90+
.Kotlin
91+
----
92+
include::complete-kotlin/src/main/kotlin/com/example/accessingdatajpa/CustomerRepository.kt[]
93+
----
8394
====
8495

8596
`CustomerRepository` extends the `CrudRepository` interface. The type of entity and ID
@@ -101,29 +112,39 @@ Now you can wire up this example and see what it looks like!
101112
== Create an Application Class
102113

103114
Spring Initializr creates a simple class for the application. The following listing shows
104-
the class that Initializr created for this example (in
105-
`src/main/java/com/example/accessingdatajpa/AccessingDataJpaApplication.java`):
115+
the class that Initializr created for this example:
106116

107117
====
108-
[source,java,tabsize=2]
118+
[source,java,indent=0,subs="verbatim,quotes",role="primary"]
119+
.Java
109120
----
110121
include::initial/src/main/java/com/example/accessingdatajpa/AccessingDataJpaApplication.java[]
111122
----
123+
[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
124+
.Kotlin
125+
----
126+
include::initial-kotlin/src/main/kotlin/com/example/accessingdatajpa/AccessingDataJpaApplication.kt[]
127+
----
112128
====
113129

114130
include::https://raw.githubusercontent.com/spring-guides/getting-started-macros/main/spring-boot-application-new-path.adoc[]
115131

116132
Now you need to modify the simple class that the Initializr created for you. To get output
117133
(to the console, in this example), you need to set up a logger. Then you need to set up
118134
some data and use it to generate output. The following listing shows the finished
119-
`AccessingDataJpaApplication` class (in
120-
`src/main/java/com/example/accessingdatajpa/AccessingDataJpaApplication.java`):
135+
`AccessingDataJpaApplication` class:
121136

122137
====
123-
[source,java,tabsize=2]
138+
[source,java,indent=0,subs="verbatim,quotes",role="primary"]
139+
.Java
124140
----
125141
include::complete/src/main/java/com/example/accessingdatajpa/AccessingDataJpaApplication.java[]
126142
----
143+
[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
144+
.Kotlin
145+
----
146+
include::complete-kotlin/src/main/kotlin/com/example/accessingdatajpa/AccessingDataJpaApplication.kt[]
147+
----
127148
====
128149

129150
The `AccessingDataJpaApplication` class includes a `demo()` method that puts the `CustomerRepository` through a few tests. First, it fetches the `CustomerRepository` from the Spring application context. Then it saves a handful of `Customer` objects, demonstrating the `save()` method and setting up some data to work with. Next, it calls `findAll()` to fetch all `Customer` objects from the database. Then it calls `findById()` to fetch a single `Customer` by its ID. Finally, it calls `findByLastName()` to find all customers whose last name is "Bauer". The `demo()` method returns a `CommandLineRunner` bean that automatically runs the code when the application launches.

0 commit comments

Comments
 (0)