summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--spring-boot/00-config/pom.xml51
-rw-r--r--spring-boot/01-quick-start/.gitignore1
-rw-r--r--spring-boot/01-quick-start/README8
-rw-r--r--spring-boot/01-quick-start/pom.xml15
-rw-r--r--spring-boot/01-quick-start/src/main/java/hello/SampleController.java31
-rw-r--r--spring-boot/02-structure/.gitignore1
-rw-r--r--spring-boot/02-structure/README1
-rw-r--r--spring-boot/02-structure/pom.xml15
-rw-r--r--spring-boot/02-structure/src/main/java/com/example/spring/Application.java20
-rw-r--r--spring-boot/02-structure/src/main/java/com/example/spring/hello/HelloController.java19
-rw-r--r--spring-boot/02-structure/src/main/resources/application.properties10
-rw-r--r--spring-boot/02-structure/src/main/resources/config/application-default.properties1
-rw-r--r--spring-boot/02-structure/src/main/resources/config/application-dev.properties1
-rw-r--r--spring-boot/02-structure/src/main/resources/config/application-production.properties0
-rw-r--r--spring-boot/03-bank-jdbc-rest/.gitignore1
-rw-r--r--spring-boot/03-bank-jdbc-rest/db-schema/mariadb-schema.sql4
-rw-r--r--spring-boot/03-bank-jdbc-rest/db-schema/postgressql-schema.sql10
-rw-r--r--spring-boot/03-bank-jdbc-rest/pom.xml31
-rw-r--r--spring-boot/03-bank-jdbc-rest/src/main/java/com/example/spring/Application.java12
-rw-r--r--spring-boot/03-bank-jdbc-rest/src/main/java/com/example/spring/bank/account/Account.java21
-rw-r--r--spring-boot/03-bank-jdbc-rest/src/main/java/com/example/spring/bank/account/AccountController.java23
-rw-r--r--spring-boot/03-bank-jdbc-rest/src/main/java/com/example/spring/bank/account/AccountManager.java21
-rw-r--r--spring-boot/03-bank-jdbc-rest/src/main/java/com/example/spring/bank/account/AccountManagerImpl.java78
-rw-r--r--spring-boot/03-bank-jdbc-rest/src/main/java/com/example/spring/bank/account/AccountRepository.java13
-rw-r--r--spring-boot/03-bank-jdbc-rest/src/main/java/com/example/spring/bank/account/JDBCAccountRepository.java82
-rw-r--r--spring-boot/03-bank-jdbc-rest/src/main/java/com/example/spring/hello/HelloController.java14
-rw-r--r--spring-boot/03-bank-jdbc-rest/src/main/resources/application.properties14
-rw-r--r--spring-boot/03-bank-jdbc-rest/src/main/resources/config/application-default.properties0
-rw-r--r--spring-boot/03-bank-jdbc-rest/src/main/resources/config/application-dev.properties0
-rw-r--r--spring-boot/03-bank-jdbc-rest/src/main/resources/config/application-production.properties0
-rw-r--r--spring-boot/04-bank-jpa-rest/.gitignore1
-rw-r--r--spring-boot/04-bank-jpa-rest/README2
-rw-r--r--spring-boot/04-bank-jpa-rest/pom.xml31
-rw-r--r--spring-boot/04-bank-jpa-rest/src/main/java/com/example/spring/Application.java12
-rw-r--r--spring-boot/04-bank-jpa-rest/src/main/java/com/example/spring/bank/account/Account.java53
-rw-r--r--spring-boot/04-bank-jpa-rest/src/main/java/com/example/spring/bank/account/AccountController.java28
-rw-r--r--spring-boot/04-bank-jpa-rest/src/main/java/com/example/spring/bank/account/AccountManager.java13
-rw-r--r--spring-boot/04-bank-jpa-rest/src/main/java/com/example/spring/bank/account/AccountManagerImpl.java33
-rw-r--r--spring-boot/04-bank-jpa-rest/src/main/java/com/example/spring/bank/account/AccountRepository.java7
-rw-r--r--spring-boot/04-bank-jpa-rest/src/main/java/com/example/spring/bank/customer/Customer.java66
-rw-r--r--spring-boot/04-bank-jpa-rest/src/main/java/com/example/spring/bank/customer/CustomerManager.java17
-rw-r--r--spring-boot/04-bank-jpa-rest/src/main/java/com/example/spring/bank/customer/CustomerManagerImpl.java45
-rw-r--r--spring-boot/04-bank-jpa-rest/src/main/java/com/example/spring/bank/customer/CustomerRepository.java7
-rw-r--r--spring-boot/04-bank-jpa-rest/src/main/java/com/example/spring/bank/dev/AppInit.java44
-rw-r--r--spring-boot/04-bank-jpa-rest/src/main/java/com/example/spring/hello/HelloController.java14
-rw-r--r--spring-boot/04-bank-jpa-rest/src/main/resources/application.properties21
-rw-r--r--spring-boot/04-bank-jpa-rest/src/main/resources/config/application-default.properties0
-rw-r--r--spring-boot/04-bank-jpa-rest/src/main/resources/config/application-dev.properties1
-rw-r--r--spring-boot/04-bank-jpa-rest/src/main/resources/config/application-production.properties0
-rw-r--r--spring-boot/05-bank-rest-client/.gitignore1
-rw-r--r--spring-boot/05-bank-rest-client/pom.xml28
-rw-r--r--spring-boot/05-bank-rest-client/src/main/java/com/example/spring/Application.java12
-rw-r--r--spring-boot/05-bank-rest-client/src/main/java/com/example/spring/bank/account/Account.java27
-rw-r--r--spring-boot/05-bank-rest-client/src/main/java/com/example/spring/bank/account/AccountService.java24
-rw-r--r--spring-boot/05-bank-rest-client/src/main/java/com/example/spring/bank/restclient/test/AccForm.java13
-rw-r--r--spring-boot/05-bank-rest-client/src/main/java/com/example/spring/bank/restclient/test/RestClientTest.java46
-rw-r--r--spring-boot/05-bank-rest-client/src/main/resources/application.properties12
-rw-r--r--spring-boot/05-bank-rest-client/src/main/resources/templates/form.html17
-rw-r--r--spring-boot/05-bank-rest-client/src/main/resources/templates/index.html16
-rw-r--r--spring-boot/05-bank-rest-client/src/main/resources/templates/result.html15
60 files changed, 1104 insertions, 0 deletions
diff --git a/spring-boot/00-config/pom.xml b/spring-boot/00-config/pom.xml
new file mode 100644
index 0000000..1c134cf
--- /dev/null
+++ b/spring-boot/00-config/pom.xml
@@ -0,0 +1,51 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <!-- Inherit defaults from Spring Boot -->
+ <parent>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-parent</artifactId>
+ <version>4.0.6</version>
+ <relativePath/> <!-- lookup parent from repository -->
+ </parent>
+
+ <properties>
+ <java.version>25</java.version>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-webmvc</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-tomcat</artifactId>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-webmvc-test</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <groupId>com.example.spring.boot</groupId>
+ <artifactId>base-config</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+ <packaging>pom</packaging>
+
+ <build>
+ <plugins>
+ <!-- Package as an executable jar -->
+ <plugin>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-maven-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/spring-boot/01-quick-start/.gitignore b/spring-boot/01-quick-start/.gitignore
new file mode 100644
index 0000000..eb5a316
--- /dev/null
+++ b/spring-boot/01-quick-start/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/spring-boot/01-quick-start/README b/spring-boot/01-quick-start/README
new file mode 100644
index 0000000..35b5fc7
--- /dev/null
+++ b/spring-boot/01-quick-start/README
@@ -0,0 +1,8 @@
+ Run:
+ $ mvn spring-boot:run
+
+ Create jar:
+ $ mvn package
+
+ Run jar:
+ $ java -jar created-jar-file-x.x.x.jar \ No newline at end of file
diff --git a/spring-boot/01-quick-start/pom.xml b/spring-boot/01-quick-start/pom.xml
new file mode 100644
index 0000000..d39a6e5
--- /dev/null
+++ b/spring-boot/01-quick-start/pom.xml
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>com.example.spring.boot</groupId>
+ <artifactId>base-config</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+ <relativePath>../00-config</relativePath>
+ </parent>
+
+ <artifactId>quick-start</artifactId>
+
+</project>
diff --git a/spring-boot/01-quick-start/src/main/java/hello/SampleController.java b/spring-boot/01-quick-start/src/main/java/hello/SampleController.java
new file mode 100644
index 0000000..b0401aa
--- /dev/null
+++ b/spring-boot/01-quick-start/src/main/java/hello/SampleController.java
@@ -0,0 +1,31 @@
+package hello;
+
+import org.springframework.boot.*;
+import org.springframework.boot.autoconfigure.*;
+import org.springframework.stereotype.*;
+import org.springframework.web.bind.annotation.*;
+
+/**
+ *
+ * @Controller - Indicates that an annotated class is a "Controller" (e.g. a web controller). This annotation serves as a specialization of @Component.
+ * @EnableAutoConfiguration - This annotation tells Spring Boot to "guess" how you want to configure Spring, based on the jar dependencies that you have added.
+ *
+ * @RequestMapping - Map the url pattern to a method
+ * @ResponseBody - Annotation that indicates a method return value should be bound to the web response body.
+ *
+ */
+@Controller
+@EnableAutoConfiguration
+public class SampleController {
+
+ @RequestMapping("/")
+ @ResponseBody
+ String home() {
+ return "Hello World!";
+ }
+
+ public static void main(String[] args) throws Exception {
+ SpringApplication.run(SampleController.class, args);
+ }
+}
+
diff --git a/spring-boot/02-structure/.gitignore b/spring-boot/02-structure/.gitignore
new file mode 100644
index 0000000..eb5a316
--- /dev/null
+++ b/spring-boot/02-structure/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/spring-boot/02-structure/README b/spring-boot/02-structure/README
new file mode 100644
index 0000000..bcbbb4f
--- /dev/null
+++ b/spring-boot/02-structure/README
@@ -0,0 +1 @@
+In the application.properties file, change the active profile to dev and run to see the difference.
diff --git a/spring-boot/02-structure/pom.xml b/spring-boot/02-structure/pom.xml
new file mode 100644
index 0000000..17e5390
--- /dev/null
+++ b/spring-boot/02-structure/pom.xml
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>com.example.spring.boot</groupId>
+ <artifactId>base-config</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+ <relativePath>../00-config</relativePath>
+ </parent>
+
+ <artifactId>structure</artifactId>
+
+</project>
diff --git a/spring-boot/02-structure/src/main/java/com/example/spring/Application.java b/spring-boot/02-structure/src/main/java/com/example/spring/Application.java
new file mode 100644
index 0000000..c051033
--- /dev/null
+++ b/spring-boot/02-structure/src/main/java/com/example/spring/Application.java
@@ -0,0 +1,20 @@
+package com.example.spring;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+/**
+ * @SpringBootApplication - Indicates a configuration class that declares one or
+ * more @Bean methods and also triggers
+ * auto-configuration and component scanning. This is a
+ * convenience annotation that is equivalent to
+ * declaring @Configuration, @EnableAutoConfiguration
+ * and @ComponentScan.
+ */
+@SpringBootApplication
+public class Application {
+
+ public static void main(String[] args) throws Exception {
+ SpringApplication.run(Application.class, args);
+ }
+} \ No newline at end of file
diff --git a/spring-boot/02-structure/src/main/java/com/example/spring/hello/HelloController.java b/spring-boot/02-structure/src/main/java/com/example/spring/hello/HelloController.java
new file mode 100644
index 0000000..ad89d9d
--- /dev/null
+++ b/spring-boot/02-structure/src/main/java/com/example/spring/hello/HelloController.java
@@ -0,0 +1,19 @@
+package com.example.spring.hello;
+
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.ResponseBody;
+
+@Controller
+public class HelloController {
+
+ @Value("${my.name}")
+ private String name;
+
+ @RequestMapping("/")
+ @ResponseBody
+ String home() {
+ return "Hello " + name + "!";
+ }
+} \ No newline at end of file
diff --git a/spring-boot/02-structure/src/main/resources/application.properties b/spring-boot/02-structure/src/main/resources/application.properties
new file mode 100644
index 0000000..480ea32
--- /dev/null
+++ b/spring-boot/02-structure/src/main/resources/application.properties
@@ -0,0 +1,10 @@
+# Possible locations of this file:
+# (Properties defined in locations higher in the list override those defined in lower locations)
+#
+# A /config subdirectory of the current directory
+# The current directory
+# A classpath /config package
+# The classpath root
+#
+
+#spring.profiles.active=dev
diff --git a/spring-boot/02-structure/src/main/resources/config/application-default.properties b/spring-boot/02-structure/src/main/resources/config/application-default.properties
new file mode 100644
index 0000000..372ce47
--- /dev/null
+++ b/spring-boot/02-structure/src/main/resources/config/application-default.properties
@@ -0,0 +1 @@
+my.name=ABC
diff --git a/spring-boot/02-structure/src/main/resources/config/application-dev.properties b/spring-boot/02-structure/src/main/resources/config/application-dev.properties
new file mode 100644
index 0000000..436a73c
--- /dev/null
+++ b/spring-boot/02-structure/src/main/resources/config/application-dev.properties
@@ -0,0 +1 @@
+my.name=ABC DEV!
diff --git a/spring-boot/02-structure/src/main/resources/config/application-production.properties b/spring-boot/02-structure/src/main/resources/config/application-production.properties
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/spring-boot/02-structure/src/main/resources/config/application-production.properties
diff --git a/spring-boot/03-bank-jdbc-rest/.gitignore b/spring-boot/03-bank-jdbc-rest/.gitignore
new file mode 100644
index 0000000..eb5a316
--- /dev/null
+++ b/spring-boot/03-bank-jdbc-rest/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/spring-boot/03-bank-jdbc-rest/db-schema/mariadb-schema.sql b/spring-boot/03-bank-jdbc-rest/db-schema/mariadb-schema.sql
new file mode 100644
index 0000000..167aa55
--- /dev/null
+++ b/spring-boot/03-bank-jdbc-rest/db-schema/mariadb-schema.sql
@@ -0,0 +1,4 @@
+CREATE TABLE account (
+ account_number int(11) primary key NOT NULL AUTO_INCREMENT,
+ balance float DEFAULT NULL
+) Engine=InnoDB;
diff --git a/spring-boot/03-bank-jdbc-rest/db-schema/postgressql-schema.sql b/spring-boot/03-bank-jdbc-rest/db-schema/postgressql-schema.sql
new file mode 100644
index 0000000..6ed17fa
--- /dev/null
+++ b/spring-boot/03-bank-jdbc-rest/db-schema/postgressql-schema.sql
@@ -0,0 +1,10 @@
+CREATE TABLE account (
+ account_number int(11) primary key NOT NULL,
+ balance float DEFAULT NULL
+);
+
+CREATE SEQUENCE account_account_number_seq;
+
+ALTER TABLE account
+ ALTER COLUMN account_number
+ SET DEFAULT NEXTVAL('account_account_number_seq'); \ No newline at end of file
diff --git a/spring-boot/03-bank-jdbc-rest/pom.xml b/spring-boot/03-bank-jdbc-rest/pom.xml
new file mode 100644
index 0000000..080425f
--- /dev/null
+++ b/spring-boot/03-bank-jdbc-rest/pom.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>com.example.spring.boot</groupId>
+ <artifactId>base-config</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+ <relativePath>../00-config</relativePath>
+ </parent>
+
+ <artifactId>bank-jdbc-rest</artifactId>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-jdbc</artifactId>
+ </dependency>
+
+ <!-- Source: https://mvnrepository.com/artifact/org.mariadb.jdbc/mariadb-java-client -->
+ <dependency>
+ <groupId>org.mariadb.jdbc</groupId>
+ <artifactId>mariadb-java-client</artifactId>
+ <version>3.5.8</version>
+ <scope>compile</scope>
+ </dependency>
+ </dependencies>
+
+</project> \ No newline at end of file
diff --git a/spring-boot/03-bank-jdbc-rest/src/main/java/com/example/spring/Application.java b/spring-boot/03-bank-jdbc-rest/src/main/java/com/example/spring/Application.java
new file mode 100644
index 0000000..4393f3f
--- /dev/null
+++ b/spring-boot/03-bank-jdbc-rest/src/main/java/com/example/spring/Application.java
@@ -0,0 +1,12 @@
+package com.example.spring;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+@SpringBootApplication
+public class Application {
+
+ public static void main(String[] args) throws Exception {
+ SpringApplication.run(Application.class, args);
+ }
+} \ No newline at end of file
diff --git a/spring-boot/03-bank-jdbc-rest/src/main/java/com/example/spring/bank/account/Account.java b/spring-boot/03-bank-jdbc-rest/src/main/java/com/example/spring/bank/account/Account.java
new file mode 100644
index 0000000..4a84f09
--- /dev/null
+++ b/spring-boot/03-bank-jdbc-rest/src/main/java/com/example/spring/bank/account/Account.java
@@ -0,0 +1,21 @@
+package com.example.spring.bank.account;
+
+import java.math.BigDecimal;
+
+public class Account {
+ private int accountNumber;
+ private BigDecimal balance;
+
+ public int getAccountNumber() {
+ return accountNumber;
+ }
+ public void setAccountNumber(int accountNumber) {
+ this.accountNumber = accountNumber;
+ }
+ public BigDecimal getBalance() {
+ return balance;
+ }
+ public void setBalance(BigDecimal balance) {
+ this.balance = balance;
+ }
+}
diff --git a/spring-boot/03-bank-jdbc-rest/src/main/java/com/example/spring/bank/account/AccountController.java b/spring-boot/03-bank-jdbc-rest/src/main/java/com/example/spring/bank/account/AccountController.java
new file mode 100644
index 0000000..9d229fe
--- /dev/null
+++ b/spring-boot/03-bank-jdbc-rest/src/main/java/com/example/spring/bank/account/AccountController.java
@@ -0,0 +1,23 @@
+package com.example.spring.bank.account;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+@RestController
+@RequestMapping("/account")
+public class AccountController {
+
+ @Autowired
+ private AccountManager accountManager;
+
+ @GetMapping("/{accno}")
+ public Account getAccount(@PathVariable Integer accno) {
+ Account account = accountManager.find(accno);
+
+ return account;
+ }
+
+} \ No newline at end of file
diff --git a/spring-boot/03-bank-jdbc-rest/src/main/java/com/example/spring/bank/account/AccountManager.java b/spring-boot/03-bank-jdbc-rest/src/main/java/com/example/spring/bank/account/AccountManager.java
new file mode 100644
index 0000000..492ecf9
--- /dev/null
+++ b/spring-boot/03-bank-jdbc-rest/src/main/java/com/example/spring/bank/account/AccountManager.java
@@ -0,0 +1,21 @@
+package com.example.spring.bank.account;
+
+import java.math.BigDecimal;
+
+public interface AccountManager {
+
+ public Account create();
+
+ public Account find(int accountNumber);
+
+ public Account deposit(int accountNumber, BigDecimal amount);
+ public Account withdraw(int accountNumber, BigDecimal amount);
+
+ public void delete(int accountNumber);
+
+ /** Returns the first account */
+ public Account transfer(int accountNumber1, int accountNumber2, BigDecimal amount);
+
+ public void chargeForLowBalance(BigDecimal minimumBalance, BigDecimal amount);
+
+}
diff --git a/spring-boot/03-bank-jdbc-rest/src/main/java/com/example/spring/bank/account/AccountManagerImpl.java b/spring-boot/03-bank-jdbc-rest/src/main/java/com/example/spring/bank/account/AccountManagerImpl.java
new file mode 100644
index 0000000..d205e02
--- /dev/null
+++ b/spring-boot/03-bank-jdbc-rest/src/main/java/com/example/spring/bank/account/AccountManagerImpl.java
@@ -0,0 +1,78 @@
+package com.example.spring.bank.account;
+
+import java.math.BigDecimal;
+import java.util.Iterator;
+import java.util.List;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+@Service
+public class AccountManagerImpl implements AccountManager {
+
+ @Autowired
+ private AccountRepository accountDAO;
+
+ @Override
+ @Transactional
+ public void chargeForLowBalance(BigDecimal minimumBalance, BigDecimal amount) {
+ List<Account> accounts = accountDAO.findAccountsWithLowBalance(minimumBalance);
+ for (Iterator<Account> iterator = accounts.iterator(); iterator.hasNext();) {
+ Account account = (Account) iterator.next();
+ // Check if the balance will go beyond 0. If yes, set the balance to 0
+ account.setBalance(account.getBalance().subtract(amount));
+ accountDAO.update(account);
+ }
+ }
+
+ @Override
+ @Transactional
+ public Account create() {
+ return accountDAO.createAccount();
+ }
+
+ @Override
+ public Account find(int accountNumber) {
+ return accountDAO.getAccount(accountNumber);
+ }
+
+ @Override
+ @Transactional
+ public void delete(int accountNumber) {
+ accountDAO.delete(accountNumber);
+ }
+
+ @Override
+ @Transactional
+ public Account deposit(int accountNumber, BigDecimal amount) {
+ Account account = accountDAO.getAccount(accountNumber);
+ account.setBalance(account.getBalance().add(amount));
+ accountDAO.update(account);
+
+ return account;
+ }
+
+ @Override
+ public Account withdraw(int accountNumber, BigDecimal amount) {
+ Account account = accountDAO.getAccount(accountNumber);
+ account.setBalance(account.getBalance().subtract(amount));
+ accountDAO.update(account);
+
+ return account;
+ }
+
+ @Override
+ @Transactional
+ public Account transfer(int accountNumber1, int accountNumber2, BigDecimal amount) {
+ Account account1 = accountDAO.getAccount(accountNumber1);
+ account1.setBalance(account1.getBalance().subtract(amount));
+ accountDAO.update(account1);
+
+ Account account2 = accountDAO.getAccount(accountNumber2);
+ account2.setBalance(account2.getBalance().add(amount));
+ accountDAO.update(account2);
+
+ return account1;
+ }
+} \ No newline at end of file
diff --git a/spring-boot/03-bank-jdbc-rest/src/main/java/com/example/spring/bank/account/AccountRepository.java b/spring-boot/03-bank-jdbc-rest/src/main/java/com/example/spring/bank/account/AccountRepository.java
new file mode 100644
index 0000000..2b5c3d0
--- /dev/null
+++ b/spring-boot/03-bank-jdbc-rest/src/main/java/com/example/spring/bank/account/AccountRepository.java
@@ -0,0 +1,13 @@
+package com.example.spring.bank.account;
+
+import java.math.BigDecimal;
+import java.util.List;
+
+public interface AccountRepository {
+ public Account createAccount();
+ public Account getAccount(int accountNumber);
+ public void update(Account account);
+ public void delete(int accountNumber);
+ public List<Account> findAllAccounts();
+ public List<Account> findAccountsWithLowBalance(BigDecimal lessThanAmount);
+}
diff --git a/spring-boot/03-bank-jdbc-rest/src/main/java/com/example/spring/bank/account/JDBCAccountRepository.java b/spring-boot/03-bank-jdbc-rest/src/main/java/com/example/spring/bank/account/JDBCAccountRepository.java
new file mode 100644
index 0000000..9ad846e
--- /dev/null
+++ b/spring-boot/03-bank-jdbc-rest/src/main/java/com/example/spring/bank/account/JDBCAccountRepository.java
@@ -0,0 +1,82 @@
+package com.example.spring.bank.account;
+
+import java.math.BigDecimal;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.List;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.jdbc.core.PreparedStatementCreator;
+import org.springframework.jdbc.core.RowMapper;
+import org.springframework.jdbc.support.GeneratedKeyHolder;
+import org.springframework.jdbc.support.KeyHolder;
+import org.springframework.stereotype.Repository;
+
+@Repository
+public class JDBCAccountRepository implements AccountRepository {
+
+ @Autowired
+ private JdbcTemplate jdbcTemplate;
+
+ @Override
+ public Account createAccount() {
+ final String INSERT_SQL = "insert into account (balance) values(0)";
+
+ KeyHolder keyHolder = new GeneratedKeyHolder();
+ jdbcTemplate.update(
+ new PreparedStatementCreator() {
+ public PreparedStatement createPreparedStatement(Connection connection) throws SQLException {
+ PreparedStatement ps =
+ connection.prepareStatement(INSERT_SQL, new String[] {"account_number"});
+ // ps.setString(1, name);
+ return ps;
+ }
+ }, keyHolder);
+
+ Account account = new Account();
+ // keyHolder.getKey() now contains the generated key
+ account.setAccountNumber(keyHolder.getKey().intValue());
+ account.setBalance(new BigDecimal("0.0"));
+
+ return account;
+ }
+
+ @Override
+ public void delete(int accountNumber) {
+ jdbcTemplate.update("delete from account where account_number = ?", Integer.valueOf(accountNumber));
+ }
+
+ @Override
+ public List<Account> findAccountsWithLowBalance(BigDecimal lessThanAmount) {
+ return this.jdbcTemplate.query( "select * from account where balance < ?", new Object[] {lessThanAmount.doubleValue()}, new AccountMapper());
+ }
+
+ @Override
+ public List<Account> findAllAccounts() {
+ return this.jdbcTemplate.query( "select * from account", new AccountMapper());
+ }
+
+ @Override
+ public Account getAccount(int accountNumber) {
+ return this.jdbcTemplate.queryForObject( "select * from account where account_number = ?", new Object[] {accountNumber}, new AccountMapper());
+ }
+
+ @Override
+ public void update(Account account) {
+ this.jdbcTemplate.update("update account set balance = ? where account_number = ?", account.getBalance(), account.getAccountNumber());
+ }
+
+
+ private static final class AccountMapper implements RowMapper<Account> {
+
+ public Account mapRow(ResultSet rs, int rowNum) throws SQLException {
+ Account account = new Account();
+ account.setAccountNumber(rs.getInt("account_number"));
+ account.setBalance(rs.getBigDecimal("balance"));
+ return account;
+ }
+ }
+} \ No newline at end of file
diff --git a/spring-boot/03-bank-jdbc-rest/src/main/java/com/example/spring/hello/HelloController.java b/spring-boot/03-bank-jdbc-rest/src/main/java/com/example/spring/hello/HelloController.java
new file mode 100644
index 0000000..bb287ba
--- /dev/null
+++ b/spring-boot/03-bank-jdbc-rest/src/main/java/com/example/spring/hello/HelloController.java
@@ -0,0 +1,14 @@
+package com.example.spring.hello;
+
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.ResponseBody;
+
+@Controller
+public class HelloController {
+ @RequestMapping("/")
+ @ResponseBody
+ String home() {
+ return "App is running! Access http://host:port/account/{accountNumber}";
+ }
+} \ No newline at end of file
diff --git a/spring-boot/03-bank-jdbc-rest/src/main/resources/application.properties b/spring-boot/03-bank-jdbc-rest/src/main/resources/application.properties
new file mode 100644
index 0000000..a46ad0c
--- /dev/null
+++ b/spring-boot/03-bank-jdbc-rest/src/main/resources/application.properties
@@ -0,0 +1,14 @@
+# Possible locations of this file:
+# (Properties defined in locations higher in the list override those defined in lower locations)
+#
+# A /config subdirectory of the current directory
+# The current directory
+# A classpath /config package
+# The classpath root
+#
+
+spring.profiles.active=dev
+
+spring.datasource.url=jdbc:mariadb://localhost:3306/bankdb
+spring.datasource.username=bankdbuser
+spring.datasource.password=abc123
diff --git a/spring-boot/03-bank-jdbc-rest/src/main/resources/config/application-default.properties b/spring-boot/03-bank-jdbc-rest/src/main/resources/config/application-default.properties
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/spring-boot/03-bank-jdbc-rest/src/main/resources/config/application-default.properties
diff --git a/spring-boot/03-bank-jdbc-rest/src/main/resources/config/application-dev.properties b/spring-boot/03-bank-jdbc-rest/src/main/resources/config/application-dev.properties
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/spring-boot/03-bank-jdbc-rest/src/main/resources/config/application-dev.properties
diff --git a/spring-boot/03-bank-jdbc-rest/src/main/resources/config/application-production.properties b/spring-boot/03-bank-jdbc-rest/src/main/resources/config/application-production.properties
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/spring-boot/03-bank-jdbc-rest/src/main/resources/config/application-production.properties
diff --git a/spring-boot/04-bank-jpa-rest/.gitignore b/spring-boot/04-bank-jpa-rest/.gitignore
new file mode 100644
index 0000000..eb5a316
--- /dev/null
+++ b/spring-boot/04-bank-jpa-rest/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/spring-boot/04-bank-jpa-rest/README b/spring-boot/04-bank-jpa-rest/README
new file mode 100644
index 0000000..be4b589
--- /dev/null
+++ b/spring-boot/04-bank-jpa-rest/README
@@ -0,0 +1,2 @@
+Run:
+ $ mvn spring-boot:run \ No newline at end of file
diff --git a/spring-boot/04-bank-jpa-rest/pom.xml b/spring-boot/04-bank-jpa-rest/pom.xml
new file mode 100644
index 0000000..2350516
--- /dev/null
+++ b/spring-boot/04-bank-jpa-rest/pom.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>com.example.spring.boot</groupId>
+ <artifactId>base-config</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+ <relativePath>../00-config</relativePath>
+ </parent>
+
+ <artifactId>bank-jpa-rest</artifactId>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-data-jpa</artifactId>
+ </dependency>
+
+ <!-- Source: https://mvnrepository.com/artifact/org.mariadb.jdbc/mariadb-java-client -->
+ <dependency>
+ <groupId>org.mariadb.jdbc</groupId>
+ <artifactId>mariadb-java-client</artifactId>
+ <version>3.5.8</version>
+ <scope>compile</scope>
+ </dependency>
+ </dependencies>
+
+</project>
diff --git a/spring-boot/04-bank-jpa-rest/src/main/java/com/example/spring/Application.java b/spring-boot/04-bank-jpa-rest/src/main/java/com/example/spring/Application.java
new file mode 100644
index 0000000..4393f3f
--- /dev/null
+++ b/spring-boot/04-bank-jpa-rest/src/main/java/com/example/spring/Application.java
@@ -0,0 +1,12 @@
+package com.example.spring;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+@SpringBootApplication
+public class Application {
+
+ public static void main(String[] args) throws Exception {
+ SpringApplication.run(Application.class, args);
+ }
+} \ No newline at end of file
diff --git a/spring-boot/04-bank-jpa-rest/src/main/java/com/example/spring/bank/account/Account.java b/spring-boot/04-bank-jpa-rest/src/main/java/com/example/spring/bank/account/Account.java
new file mode 100644
index 0000000..b5fe811
--- /dev/null
+++ b/spring-boot/04-bank-jpa-rest/src/main/java/com/example/spring/bank/account/Account.java
@@ -0,0 +1,53 @@
+package com.example.spring.bank.account;
+
+import java.math.BigDecimal;
+
+import com.example.spring.bank.customer.Customer;
+
+import jakarta.persistence.Entity;
+import jakarta.persistence.GeneratedValue;
+import jakarta.persistence.GenerationType;
+import jakarta.persistence.Id;
+import jakarta.persistence.ManyToOne;
+
+@Entity
+public class Account {
+ @Id
+ @GeneratedValue(strategy = GenerationType.AUTO)
+ private Long accountNumber;
+
+ private BigDecimal balance;
+
+ public Account() {
+ super();
+ }
+
+ public Account(BigDecimal balance) {
+ super();
+ this.balance = balance;
+ }
+
+ @ManyToOne
+ private Customer customer;
+
+ public Customer getCustomer() {
+ return customer;
+ }
+
+ public void setCustomer(Customer customer) {
+ this.customer = customer;
+ }
+
+ public Long getAccountNumber() {
+ return accountNumber;
+ }
+ public void setAccountNumber(Long accountNumber) {
+ this.accountNumber = accountNumber;
+ }
+ public BigDecimal getBalance() {
+ return balance;
+ }
+ public void setBalance(BigDecimal balance) {
+ this.balance = balance;
+ }
+} \ No newline at end of file
diff --git a/spring-boot/04-bank-jpa-rest/src/main/java/com/example/spring/bank/account/AccountController.java b/spring-boot/04-bank-jpa-rest/src/main/java/com/example/spring/bank/account/AccountController.java
new file mode 100644
index 0000000..dc017dd
--- /dev/null
+++ b/spring-boot/04-bank-jpa-rest/src/main/java/com/example/spring/bank/account/AccountController.java
@@ -0,0 +1,28 @@
+package com.example.spring.bank.account;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+@RestController
+@RequestMapping("/account")
+public class AccountController {
+
+ @Autowired
+ private AccountManager accountManager;
+
+ @GetMapping("/{accountNumber}")
+ public Account getAccount(@PathVariable Long accountNumber) {
+ // TODO: Check null returns.
+ Account account = accountManager.findByAccountNumber(accountNumber).get();
+ return account;
+ }
+
+ @PostMapping("/")
+ public Account createAccount(Account account) {
+ return accountManager.create(account);
+ }
+} \ No newline at end of file
diff --git a/spring-boot/04-bank-jpa-rest/src/main/java/com/example/spring/bank/account/AccountManager.java b/spring-boot/04-bank-jpa-rest/src/main/java/com/example/spring/bank/account/AccountManager.java
new file mode 100644
index 0000000..14dfa0c
--- /dev/null
+++ b/spring-boot/04-bank-jpa-rest/src/main/java/com/example/spring/bank/account/AccountManager.java
@@ -0,0 +1,13 @@
+package com.example.spring.bank.account;
+
+import java.util.Optional;
+
+public interface AccountManager {
+
+ public Account create(Account account);
+
+ public Optional<Account> findByAccountNumber(Long accountNumber);
+ public Iterable<Account> findAll();
+
+ // Other methods
+}
diff --git a/spring-boot/04-bank-jpa-rest/src/main/java/com/example/spring/bank/account/AccountManagerImpl.java b/spring-boot/04-bank-jpa-rest/src/main/java/com/example/spring/bank/account/AccountManagerImpl.java
new file mode 100644
index 0000000..2227469
--- /dev/null
+++ b/spring-boot/04-bank-jpa-rest/src/main/java/com/example/spring/bank/account/AccountManagerImpl.java
@@ -0,0 +1,33 @@
+package com.example.spring.bank.account;
+
+import java.util.Optional;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import jakarta.transaction.Transactional;
+
+@Service
+public class AccountManagerImpl implements AccountManager {
+
+ @Autowired
+ private AccountRepository accountRepository;
+
+ @Override
+ @Transactional
+ public Account create(Account account) {
+ return accountRepository.save(account);
+ }
+
+ @Override
+ public Optional<Account> findByAccountNumber(Long accountNumber) {
+ return accountRepository.findById(accountNumber);
+ }
+
+ @Override
+ public Iterable<Account> findAll() {
+ return accountRepository.findAll();
+ }
+
+ // Other methods
+} \ No newline at end of file
diff --git a/spring-boot/04-bank-jpa-rest/src/main/java/com/example/spring/bank/account/AccountRepository.java b/spring-boot/04-bank-jpa-rest/src/main/java/com/example/spring/bank/account/AccountRepository.java
new file mode 100644
index 0000000..086f828
--- /dev/null
+++ b/spring-boot/04-bank-jpa-rest/src/main/java/com/example/spring/bank/account/AccountRepository.java
@@ -0,0 +1,7 @@
+package com.example.spring.bank.account;
+
+import org.springframework.data.repository.ListCrudRepository;
+
+public interface AccountRepository extends ListCrudRepository<Account, Long> {
+
+} \ No newline at end of file
diff --git a/spring-boot/04-bank-jpa-rest/src/main/java/com/example/spring/bank/customer/Customer.java b/spring-boot/04-bank-jpa-rest/src/main/java/com/example/spring/bank/customer/Customer.java
new file mode 100644
index 0000000..43bf0a6
--- /dev/null
+++ b/spring-boot/04-bank-jpa-rest/src/main/java/com/example/spring/bank/customer/Customer.java
@@ -0,0 +1,66 @@
+package com.example.spring.bank.customer;
+
+import java.util.List;
+
+import com.example.spring.bank.account.Account;
+
+import jakarta.persistence.Entity;
+import jakarta.persistence.GeneratedValue;
+import jakarta.persistence.GenerationType;
+import jakarta.persistence.Id;
+import jakarta.persistence.OneToMany;
+
+
+
+@Entity
+public class Customer {
+
+ @Id
+ @GeneratedValue(strategy = GenerationType.AUTO)
+ private Long id;
+
+ private String name;
+
+ public Customer() {
+ super();
+ }
+
+ public Customer(String name) {
+ super();
+ this.name = name;
+ }
+
+ @OneToMany(mappedBy = "customer")
+// @OneToMany
+ private List<Account> accounts;
+
+ public List<Account> getAccounts() {
+ return accounts;
+ }
+
+ public void setAccounts(List<Account> accounts) {
+ this.accounts = accounts;
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ @Override
+ public String toString() {
+ return "Customer [id=" + id + ", name=" + name + "]";
+ }
+
+}
diff --git a/spring-boot/04-bank-jpa-rest/src/main/java/com/example/spring/bank/customer/CustomerManager.java b/spring-boot/04-bank-jpa-rest/src/main/java/com/example/spring/bank/customer/CustomerManager.java
new file mode 100644
index 0000000..1560672
--- /dev/null
+++ b/spring-boot/04-bank-jpa-rest/src/main/java/com/example/spring/bank/customer/CustomerManager.java
@@ -0,0 +1,17 @@
+package com.example.spring.bank.customer;
+
+import java.util.Optional;
+
+import com.example.spring.bank.account.Account;
+
+public interface CustomerManager {
+
+ public Customer create(Customer customer);
+
+ public Optional<Customer> findById(Long customerId);
+ public Iterable<Customer> findAll();
+
+ public void addAccount(Customer customer, Account account);
+
+ // Other methods
+}
diff --git a/spring-boot/04-bank-jpa-rest/src/main/java/com/example/spring/bank/customer/CustomerManagerImpl.java b/spring-boot/04-bank-jpa-rest/src/main/java/com/example/spring/bank/customer/CustomerManagerImpl.java
new file mode 100644
index 0000000..05b3fdc
--- /dev/null
+++ b/spring-boot/04-bank-jpa-rest/src/main/java/com/example/spring/bank/customer/CustomerManagerImpl.java
@@ -0,0 +1,45 @@
+package com.example.spring.bank.customer;
+
+import java.util.Optional;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import com.example.spring.bank.account.Account;
+
+import jakarta.transaction.Transactional;
+
+@Service
+public class CustomerManagerImpl implements CustomerManager {
+
+ @Autowired
+ private CustomerRepository customerRepository;
+
+ @Override
+ @Transactional
+ public Customer create(Customer customer) {
+ return customerRepository.save(customer);
+ }
+
+ @Override
+ public Optional<Customer> findById(Long customerId) {
+ return customerRepository.findById(customerId);
+ }
+
+ @Override
+ public Iterable<Customer> findAll() {
+ return customerRepository.findAll();
+ }
+
+ @Transactional
+ @Override
+ public void addAccount(Customer customer, Account account) {
+ // May not work is the customer is detached.
+ // customer.getAccounts().add(account);
+
+ // Access the Customer again - so that it would not be a detached entity.
+ customerRepository.findById(customer.getId()).get().getAccounts().add(account);
+ }
+
+ // Other methods
+} \ No newline at end of file
diff --git a/spring-boot/04-bank-jpa-rest/src/main/java/com/example/spring/bank/customer/CustomerRepository.java b/spring-boot/04-bank-jpa-rest/src/main/java/com/example/spring/bank/customer/CustomerRepository.java
new file mode 100644
index 0000000..8695d66
--- /dev/null
+++ b/spring-boot/04-bank-jpa-rest/src/main/java/com/example/spring/bank/customer/CustomerRepository.java
@@ -0,0 +1,7 @@
+package com.example.spring.bank.customer;
+
+import org.springframework.data.repository.ListCrudRepository;
+
+public interface CustomerRepository extends ListCrudRepository<Customer, Long> {
+
+} \ No newline at end of file
diff --git a/spring-boot/04-bank-jpa-rest/src/main/java/com/example/spring/bank/dev/AppInit.java b/spring-boot/04-bank-jpa-rest/src/main/java/com/example/spring/bank/dev/AppInit.java
new file mode 100644
index 0000000..03a60f9
--- /dev/null
+++ b/spring-boot/04-bank-jpa-rest/src/main/java/com/example/spring/bank/dev/AppInit.java
@@ -0,0 +1,44 @@
+package com.example.spring.bank.dev;
+
+import java.math.BigDecimal;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.boot.CommandLineRunner;
+import org.springframework.stereotype.Component;
+
+import com.example.spring.bank.account.Account;
+import com.example.spring.bank.account.AccountManager;
+import com.example.spring.bank.customer.Customer;
+import com.example.spring.bank.customer.CustomerManager;
+
+@Component
+public class AppInit implements CommandLineRunner {
+
+ @Autowired
+ private AccountManager accountManager;
+
+ @Autowired
+ private CustomerManager customerManager;
+
+ @Value("${bankapp.init-testdata}")
+ private boolean initTestData;
+
+ @Override
+ public void run(String... args) throws Exception {
+ // Create test accounts.
+ if (initTestData) {
+ Account acc1 = accountManager.create(new Account(new BigDecimal("0.00")));
+ Account acc2 = accountManager.create(new Account(new BigDecimal("0.00")));
+
+ Customer c1 = customerManager.create(new Customer("Madushi"));
+ Customer c2 = customerManager.create(new Customer("Anuradha"));
+
+ Customer customerSamitha = customerManager.create(new Customer("Samitha"));
+ Account accountSamitha = accountManager.create(new Account(new BigDecimal("0.00")));
+
+ customerManager.addAccount(customerSamitha, accountSamitha);
+ }
+ }
+
+}
diff --git a/spring-boot/04-bank-jpa-rest/src/main/java/com/example/spring/hello/HelloController.java b/spring-boot/04-bank-jpa-rest/src/main/java/com/example/spring/hello/HelloController.java
new file mode 100644
index 0000000..bb287ba
--- /dev/null
+++ b/spring-boot/04-bank-jpa-rest/src/main/java/com/example/spring/hello/HelloController.java
@@ -0,0 +1,14 @@
+package com.example.spring.hello;
+
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.ResponseBody;
+
+@Controller
+public class HelloController {
+ @RequestMapping("/")
+ @ResponseBody
+ String home() {
+ return "App is running! Access http://host:port/account/{accountNumber}";
+ }
+} \ No newline at end of file
diff --git a/spring-boot/04-bank-jpa-rest/src/main/resources/application.properties b/spring-boot/04-bank-jpa-rest/src/main/resources/application.properties
new file mode 100644
index 0000000..16ae16c
--- /dev/null
+++ b/spring-boot/04-bank-jpa-rest/src/main/resources/application.properties
@@ -0,0 +1,21 @@
+# Possible locations of this file:
+# (Properties defined in locations higher in the list override those defined in lower locations)
+#
+# A /config subdirectory of the current directory
+# The current directory
+# A classpath /config package
+# The classpath root
+#
+
+spring.profiles.active=dev
+
+spring.datasource.url=jdbc:mariadb://localhost:3306/bankdb
+spring.datasource.username=bankdbuser
+spring.datasource.password=abc123
+
+spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MariaDBDialect
+
+spring.jpa.hibernate.ddl-auto=create-drop
+spring.jpa.show-sql=true
+
+bankapp.init-testdata=0
diff --git a/spring-boot/04-bank-jpa-rest/src/main/resources/config/application-default.properties b/spring-boot/04-bank-jpa-rest/src/main/resources/config/application-default.properties
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/spring-boot/04-bank-jpa-rest/src/main/resources/config/application-default.properties
diff --git a/spring-boot/04-bank-jpa-rest/src/main/resources/config/application-dev.properties b/spring-boot/04-bank-jpa-rest/src/main/resources/config/application-dev.properties
new file mode 100644
index 0000000..8dd7a1b
--- /dev/null
+++ b/spring-boot/04-bank-jpa-rest/src/main/resources/config/application-dev.properties
@@ -0,0 +1 @@
+bankapp.init-testdata=1 \ No newline at end of file
diff --git a/spring-boot/04-bank-jpa-rest/src/main/resources/config/application-production.properties b/spring-boot/04-bank-jpa-rest/src/main/resources/config/application-production.properties
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/spring-boot/04-bank-jpa-rest/src/main/resources/config/application-production.properties
diff --git a/spring-boot/05-bank-rest-client/.gitignore b/spring-boot/05-bank-rest-client/.gitignore
new file mode 100644
index 0000000..eb5a316
--- /dev/null
+++ b/spring-boot/05-bank-rest-client/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/spring-boot/05-bank-rest-client/pom.xml b/spring-boot/05-bank-rest-client/pom.xml
new file mode 100644
index 0000000..520bf43
--- /dev/null
+++ b/spring-boot/05-bank-rest-client/pom.xml
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>com.example.spring.boot</groupId>
+ <artifactId>base-config</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+ <relativePath>../00-config</relativePath>
+ </parent>
+
+ <artifactId>bank-rest-client</artifactId>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-restclient</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-thymeleaf</artifactId>
+ </dependency>
+ </dependencies>
+
+</project> \ No newline at end of file
diff --git a/spring-boot/05-bank-rest-client/src/main/java/com/example/spring/Application.java b/spring-boot/05-bank-rest-client/src/main/java/com/example/spring/Application.java
new file mode 100644
index 0000000..4393f3f
--- /dev/null
+++ b/spring-boot/05-bank-rest-client/src/main/java/com/example/spring/Application.java
@@ -0,0 +1,12 @@
+package com.example.spring;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+@SpringBootApplication
+public class Application {
+
+ public static void main(String[] args) throws Exception {
+ SpringApplication.run(Application.class, args);
+ }
+} \ No newline at end of file
diff --git a/spring-boot/05-bank-rest-client/src/main/java/com/example/spring/bank/account/Account.java b/spring-boot/05-bank-rest-client/src/main/java/com/example/spring/bank/account/Account.java
new file mode 100644
index 0000000..f9789e4
--- /dev/null
+++ b/spring-boot/05-bank-rest-client/src/main/java/com/example/spring/bank/account/Account.java
@@ -0,0 +1,27 @@
+package com.example.spring.bank.account;
+
+import java.math.BigDecimal;
+
+public class Account {
+ private int accountNumber;
+
+ private BigDecimal balance;
+
+ public int getAccountNumber() {
+ return accountNumber;
+ }
+ public void setAccountNumber(int accountNumber) {
+ this.accountNumber = accountNumber;
+ }
+ public BigDecimal getBalance() {
+ return balance;
+ }
+ public void setBalance(BigDecimal balance) {
+ this.balance = balance;
+ }
+
+ @Override
+ public String toString() {
+ return "Account [accountNumber=" + accountNumber + ", balance=" + balance + "]";
+ }
+} \ No newline at end of file
diff --git a/spring-boot/05-bank-rest-client/src/main/java/com/example/spring/bank/account/AccountService.java b/spring-boot/05-bank-rest-client/src/main/java/com/example/spring/bank/account/AccountService.java
new file mode 100644
index 0000000..c7b3804
--- /dev/null
+++ b/spring-boot/05-bank-rest-client/src/main/java/com/example/spring/bank/account/AccountService.java
@@ -0,0 +1,24 @@
+package com.example.spring.bank.account;
+
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.boot.restclient.RestTemplateBuilder;
+import org.springframework.stereotype.Service;
+import org.springframework.web.client.RestTemplate;
+
+@Service
+public class AccountService {
+
+ @Value("${rest.baseURL}")
+ private String restBaseURL;
+
+ private final RestTemplate restTemplate;
+
+ public AccountService(RestTemplateBuilder restTemplateBuilder) {
+ this.restTemplate = restTemplateBuilder.build();
+ }
+
+ public Account getAccount(Integer accno) {
+ return this.restTemplate.getForObject(restBaseURL + "/account/{accno}", Account.class, accno);
+ }
+
+} \ No newline at end of file
diff --git a/spring-boot/05-bank-rest-client/src/main/java/com/example/spring/bank/restclient/test/AccForm.java b/spring-boot/05-bank-rest-client/src/main/java/com/example/spring/bank/restclient/test/AccForm.java
new file mode 100644
index 0000000..9b58dae
--- /dev/null
+++ b/spring-boot/05-bank-rest-client/src/main/java/com/example/spring/bank/restclient/test/AccForm.java
@@ -0,0 +1,13 @@
+package com.example.spring.bank.restclient.test;
+
+public class AccForm {
+
+ private Integer accNo;
+
+ public Integer getAccNo() {
+ return accNo;
+ }
+ public void setAccNo(Integer accNo) {
+ this.accNo = accNo;
+ }
+}
diff --git a/spring-boot/05-bank-rest-client/src/main/java/com/example/spring/bank/restclient/test/RestClientTest.java b/spring-boot/05-bank-rest-client/src/main/java/com/example/spring/bank/restclient/test/RestClientTest.java
new file mode 100644
index 0000000..adf4755
--- /dev/null
+++ b/spring-boot/05-bank-rest-client/src/main/java/com/example/spring/bank/restclient/test/RestClientTest.java
@@ -0,0 +1,46 @@
+package com.example.spring.bank.restclient.test;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+import org.springframework.ui.Model;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.ModelAttribute;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.servlet.ModelAndView;
+
+import com.example.spring.bank.account.Account;
+import com.example.spring.bank.account.AccountService;
+
+@Controller
+public class RestClientTest {
+
+ @Autowired
+ private AccountService accountService;
+
+ @GetMapping("/acc")
+ public String accountForm(Model model) {
+ model.addAttribute("account", new AccForm());
+ return "form";
+ }
+
+ @PostMapping("/acc")
+ public ModelAndView accountSubmission(@ModelAttribute AccForm accForm) {
+
+ Account account = accountService.getAccount(accForm.getAccNo());
+
+ ModelAndView mav = new ModelAndView();
+ mav.addObject("account", account);
+
+ mav.setViewName("result");
+
+ return mav;
+ }
+
+
+ @RequestMapping("/")
+ public String checkAccount() {
+ return "index";
+ }
+
+}
diff --git a/spring-boot/05-bank-rest-client/src/main/resources/application.properties b/spring-boot/05-bank-rest-client/src/main/resources/application.properties
new file mode 100644
index 0000000..cf862c6
--- /dev/null
+++ b/spring-boot/05-bank-rest-client/src/main/resources/application.properties
@@ -0,0 +1,12 @@
+# Possible locations of this file:
+# (Properties defined in locations higher in the list override those defined in lower locations)
+#
+# A /config subdirectory of the current directory
+# The current directory
+# A classpath /config package
+# The classpath root
+#
+
+server.port = 8081
+
+rest.baseURL=http://localhost:8080 \ No newline at end of file
diff --git a/spring-boot/05-bank-rest-client/src/main/resources/templates/form.html b/spring-boot/05-bank-rest-client/src/main/resources/templates/form.html
new file mode 100644
index 0000000..7927b92
--- /dev/null
+++ b/spring-boot/05-bank-rest-client/src/main/resources/templates/form.html
@@ -0,0 +1,17 @@
+<!DOCTYPE HTML>
+<html xmlns:th="http://www.thymeleaf.org">
+
+<head>
+ <title>Check Account Balance</title>
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+</head>
+
+<body>
+ <h1>Form</h1>
+ <form action="#" th:action="@{/acc}" th:object="${account}" method="post">
+ <p>Account number: <input type="text" th:field="*{accNo}" /></p>
+ <p><input type="submit" value="Submit" /> <input type="reset" value="Reset" /></p>
+ </form>
+</body>
+
+</html> \ No newline at end of file
diff --git a/spring-boot/05-bank-rest-client/src/main/resources/templates/index.html b/spring-boot/05-bank-rest-client/src/main/resources/templates/index.html
new file mode 100644
index 0000000..f30a2c0
--- /dev/null
+++ b/spring-boot/05-bank-rest-client/src/main/resources/templates/index.html
@@ -0,0 +1,16 @@
+<!DOCTYPE HTML>
+<html xmlns:th="http://www.thymeleaf.org">
+
+<head>
+ <title>Check Account Balance</title>
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+</head>
+
+<body>
+
+Access <a href="/acc">/acc</a>
+
+</body>
+
+</html>
+
diff --git a/spring-boot/05-bank-rest-client/src/main/resources/templates/result.html b/spring-boot/05-bank-rest-client/src/main/resources/templates/result.html
new file mode 100644
index 0000000..15393be
--- /dev/null
+++ b/spring-boot/05-bank-rest-client/src/main/resources/templates/result.html
@@ -0,0 +1,15 @@
+<!DOCTYPE HTML>
+<html xmlns:th="http://www.thymeleaf.org">
+<head>
+ <title>Check Account Balance</title>
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+</head>
+<body>
+ <h1>Result</h1>
+
+ <p th:text="'Account number: ' + ${account.accountNumber}" />
+ <p th:text="'Balance: ' + ${account.balance}" />
+
+ <a href="/acc">Try again</a>
+</body>
+</html> \ No newline at end of file