Tech Rocks

Coldfusion
Java
JQuery

An online resource for latest web technologies like Coldfusion, JRun, Pro*C, JQuery, HTML5, PHP, W3C, Java, J2EE, C, C++, ORACLE, PL/SQL, MySql, Ajax, Coldbox, Fusebox, UNIX, JavaScript, NodeJS and much more...

Monday, September 16, 2024

Spring Boot Example

Clone the below repo using the commands on windows git bash

## Get the code
# Versions jdk 19 and spring boot 3.3.3
git clone https://github.com/jeethualex/spring.git

## Build project
gradle build
mvn clean install

## Local run
gradle bootRun

## Run the jar file - with gradle
java -jar .\build\libs\demo-0.0.1-SNAPSHOT.jar

## Run the jar file - with maven
java -jar .\target\demo-0.0.1-SNAPSHOT.jar

###### GREETINGS ######

## launch urls below 

# http://localhost:8080/hello
curl http://localhost:8080/greeting
curl http://localhost:8080/hello

# http://localhost:8080/hello?name=G2
curl http://localhost:8080/greeting?name=G2
curl http://localhost:8080/hello?name=G2


###### EMPLOYEES CRUD ######

## before running these commands will need a local mysql database server installed with 2 env variables
## will create a spring database with employee table
## Env variables needed to be added on windows are MYSQl_USER and MYSQL_PASS

## Create Employees
curl --location 'localhost:8080/employee' \
--header 'Content-Type: application/json' \
--data '{
    "name":"jeetu",
    "department":"IT"
}'

## Get all Employees
curl --location 'localhost:8080/employees' \
--header 'Content-Type: application/json'

## Get Employee
curl --location 'localhost:8080/employee/1' \
--header 'Content-Type: application/json'

## Delete Employee
curl --location --request DELETE 'localhost:8080/employee/4' \
--header 'Content-Type: application/json'

## Update Employee
curl --location --request PUT 'localhost:8080/employee' \
--header 'Content-Type: application/json' \
--data '{
    "id":"1",
    "name":"jeetu",
    "department":"HR"
}'

###### CUSTOMER JDBC ######
curl http://localhost:8080/customer?name=G2
# Check the logs for db queries

References :

0 comments :