I share example how to integration Kotlin - Spring Boot2 - Spring Data JPA-RESTful Web Service and CRUD example.
Technologies used:
1. Spring Boot 2.2.2.RELEASE
2. Gradle 2.x
3. Java 8
4. Eclipse: Oxygen.1.a Release (4.7.1a) or IntelliJ Community
5. Spring Tools Suite (STS) 4
6. Postman
7. MySql
Code on GitHub:
https://github.com/HenryXiloj/Kotlin-SpringBoot2-RESTful
Steps:
Step 1:
Execute next script on MySql
Step 2: Import project on Eclipse or IntelliJ
Eclipse:
https://github.com/HenryXiloj/Kotlin-SpringBoot2-RESTful
Steps:
Step 1:
Execute next script on MySql
CREATE TABLE users
(
id INT(11) NOT NULL auto_increment,
username VARCHAR(255) NOT NULL,
password VARCHAR(255) NOT NULL,
created TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP() on
UPDATE CURRENT_TIMESTAMP(),
PRIMARY KEY (id)
)
(
id INT(11) NOT NULL auto_increment,
username VARCHAR(255) NOT NULL,
password VARCHAR(255) NOT NULL,
created TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP() on
UPDATE CURRENT_TIMESTAMP(),
PRIMARY KEY (id)
)
Step 2: Import project on Eclipse or IntelliJ
Eclipse:
Righ click on project Gradle -> Refresh Gracle project (Eclipse)
Step 3.
Run project from directory on console next command:
Run project from directory on console next command:
./gradlew bootRun
Step 4: Test.
GET (by default)
GET all users
http://localhost:8080/ws/users
GET user by id.
http://localhost:8080/ws/users/1
POST user (save)
http://localhost:8080/ws/users
PUT user (update user)
http://localhost:8080/ws/users/1
DELETE user.
http://localhost:8080/ws/users/1
http://localhost:8080/ws/users
GET user by id.
http://localhost:8080/ws/users/1
POST user (save)
http://localhost:8080/ws/users
PUT user (update user)
http://localhost:8080/ws/users/1
DELETE user.
http://localhost:8080/ws/users/1
Great :).
References:
https://kotlinlang.org/docs/tutorials/spring-boot-restful.html
https://www.callicoder.com/kotlin-spring-boot-mysql-jpa-hibernate-rest-api-tutorial/
https://www.callicoder.com/kotlin-spring-boot-mysql-jpa-hibernate-rest-api-tutorial/