Wednesday, December 11, 2019

Kotlin SpringBoot 2 Spring Data JPA RESTful Web Service

Hi everyone.

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

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) 
             )

Step 2: Import project on Eclipse or IntelliJ


Eclipse:


IntelliJ:  File -> open --> choose folder backend




Righ click on project  Gradle -> Refresh Gracle project (Eclipse)



IntelliJ:

View -> Tool Windows -> Gradle -> Righ click on project -> Refresh Gradle dependencies



Step 3.

Run project from directory on console next command:

./gradlew bootRun



Run project from IntelliJ :

View -> Tool Windows -> Gradle -> Execute Gradle Task -> gradle 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



Great :).















References:








































No comments:

Post a Comment

Virtual Threads in Java 21: Simplified Concurrency for Modern Applications

  With Java 21, Virtual Threads have redefined how we approach concurrency, offering a lightweight and efficient way to handle parallel and ...