This is a demo application to show usage of spring framework with scala. It basically provides web interface to manipulate a mysql database.
Before running the application, there must be a customers
table with three fields: id
, first_name
and last_name
.
Run the following mysql
script in a database editor (DataGrip
etc.)
#drop if test db already exists
drop SCHEMA if EXISTS test;
#create test db
create SCHEMA test;
#use test db
use test;
# create customers table
CREATE TABLE test.customers
(
id INT PRIMARY KEY AUTO_INCREMENT,
first_name VARCHAR(100) NOT NULL,
last_name VARCHAR(100) NOT NULL
);
In application.properties
file update the database information: username
, password
The default is as follows:
#disbale Spring banner
spring.main.banner-mode=off
# Loads SQL scripts? schema.sql and data.sql
#spring.datasource.initialize=true
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/test
spring.datasource.username=root
spring.datasource.password=12345
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
# HikariCP settings
# spring.datasource.hikari.*
#60 sec
spring.datasource.hikari.connection-timeout=60000
# max 5
spring.datasource.hikari.maximum-pool-size=5
After running the application, there will be 5 web services available. You can use Postman
or curl
to test them.
- Returns the list of all customers as json list
- Returns the requested user as json object
- Deletes the specified user if exists
- Creates a new user and inserts it into database
Body:
{ "firstName":"hello", "lastName":"world" }
- Updates the specified user in the database
Body:
{ "firstName":"hello", "lastName":"universe" }