Jun 22, 2024
start.spring.io.
net.javaguidesbanking-appDemo project for Spring Boot banking appnet.java.bankingjarSpring Web: For building REST APIs.Spring Data JPA: For JPA repositories and hibernate.MySQL Driver: For connecting Spring Boot with MySQL.Lombok: To reduce boilerplate code.CREATE DATABASE banking_app;src/main/resources/application.properties.spring.datasource.url=jdbc:mysql://localhost:3306/banking_app
spring.datasource.username=root
spring.datasource.password=password
spring.jpa.hibernate.ddl-auto=update
entity: For JPA entitiescontroller: For REST controllersservice: For service layerrepository: For Spring Data JPA repositoriesdto: For data transfer objectsmapper: For converting DTOs to entities and vice versaAccount
id, accountHolderName, balance@Entity, @Table(name="accounts"), @Id, @GeneratedValue(strategy = GenerationType.IDENTITY), @Column(name="account_holder_name")AccountDto
id, accountHolderName, balance@Data, @AllArgsConstructor, @NoArgsConstructorAccountMapper
mapToAccount(AccountDto accountDto), mapToAccountDto(Account account)AccountRepository
JpaRepository<Account, Long>AccountService
createAccount(AccountDto accountDto), getAccountById(Long id), getAllAccounts(), deposit(Long id, Double amount), withdraw(Long id, Double amount), deleteAccount(Long id)AccountServiceImplAccountController
createAccount(AccountDto accountDto)getAccountById(@PathVariable Long id)getAllAccounts()deposit(@PathVariable Long id, @RequestBody Map<String, Double> request)withdraw(@PathVariable Long id, @RequestBody Map<String, Double> request)deleteAccount(@PathVariable Long id)http://localhost:8080/api/accounts{ "accountHolderName": "John Doe", "balance": 20000 }{ "id": 1, "accountHolderName": "John Doe", "balance": 20000 }http://localhost:8080/api/accounts/{id}{ "id": 1, "accountHolderName": "John Doe", "balance": 20000 }http://localhost:8080/api/accounts[{ "id": 1, "accountHolderName": "John Doe", "balance": 20000 }, { "id": 2, "accountHolderName": "Jane Doe", "balance": 15000 }]http://localhost:8080/api/accounts/{id}/deposit{ "amount": 5000 }{ "id": 1, "accountHolderName": "John Doe", "balance": 25000 }http://localhost:8080/api/accounts/{id}/withdraw{ "amount": 5000 }{ "id": 1, "accountHolderName": "John Doe", "balance": 20000 }http://localhost:8080/api/accounts/{id}Account is deleted successfully