A Spring Boot + JSP web application for basic stock trading simulation. Users can register/login, browse stocks, place buy/sell orders, manage wallet balance, and review trading history.
- Authenticates users with email/password
- Displays available stocks
- Shows stock detail pages and order entry forms
- Creates buy/sell orders in an order book
- Updates customer balance after each eligible trade
- Tracks trades in a trading history table
- Shows customer portfolio and grouped order data
- Language: Java 17
- Framework: Spring Boot 2.7.3
- Web: Spring MVC + JSP + JSTL
- Persistence: Spring Data JPA (Hibernate)
- Database: MySQL (
tradingschema) - Build tool: Maven Wrapper (
mvnw)
src/main/java/com/ab
├── OrderBookTradingApplication.java # Spring Boot entrypoint
├── controllers/ # HTTP routes + page navigation
├── models/ # JPA entities (Customer, Stock, OrderBook, TradingHistory)
├── repositories/ # Database access layer (JpaRepository + custom queries)
└── services/ # Service layer package (interfaces + implementations)
src/main/resources
└── application.properties # DB, JPA and JSP view resolver config
src/main/webapp/WEB-INF/views # JSP pages rendered by controllers
OrderBookTradingApplicationstarts the Spring Boot application context.
Customer: user account data (customerId, name, email, password,balance).Stock: stock catalog data (stockId, name, region, quantity, price).OrderBook: order records (buy/sell type, quantity, price, stock info, customer id, timestamp).TradingHistory: persisted trade events per customer and stock.
These entities are mapped with @Entity and persisted by JPA.
CustomerRepository- Login lookup by email/password (
findByRecord) - Balance update query (
modifyCustomerBalance)
- Login lookup by email/password (
StockRepository- Standard CRUD/listing via
JpaRepository
- Standard CRUD/listing via
OrderBookRepository- Standard order CRUD
- Custom native query (
showOrderBookCustomerId) that aggregates customer orders by stock
TradingHistoryRepository- Filter trading history by customer id
Service interfaces define capabilities, and *Impl classes perform repository operations.
- Customer service: register user, login user, update balance
- Stock service: list stocks and fetch stock by id
- Order book service: create orders, list/sort orders, portfolio lookup by customer
- Trading history service: create trade records, filter/sort trading history
Controllers connect routes to services and return JSP views.
CustomerMappingController/login(GET/POST),/logout/register+/registerCustomer- Stores logged-in user in session attribute:
session_customer
StockController/stocks: show stock list/stocks/chart/{...}: show selected stock chart/details page
StockMappingController/stocks/chart: direct chart page mapping
OrderBookMappingController/stocks/orderbook(POST): place order, create trading history row, update balance rules/stocks/orderbook(GET): list order book/stocks/orderbook/orderByPriceand/stocks/orderbook/orderByQuantity: sorted views
OrderBookController/portfolio: show customer portfolio (aggregated customer orders)
PortfolioController/Sell/{stockId}/{stockRegion}/{stockName}: sell page preparation
BalanceController/balance: wallet page/depositBalanceand/withdrawBalance: modify wallet and return portfolio view
TradingHistoryController/stocks/tradinghistory: customer-specific trade history view
login.jsp: login formregister.jsp: registration formstock_list.jsp: stock catalog tablestock_chart.jsp: selected stock display + order interactionorder_book.jsp: order book list and sorting accessportfolio.jsp: customer holdings/order summarybalance.jsp: wallet balance, deposit, withdraw actionstrading_history.jsp: customer trade recordssell.jsp: sell flow page for selected stocknoUser.jsp: fallback page when session/login is missing or invalid
(Additional JSPs like showOrderBook.jsp, order_history.jsp, and register_success.jsp exist as helper/legacy-style pages.)
src/main/resources/application.properties configures:
- MySQL datasource URL:
jdbc:mysql://localhost/trading - Username:
root - Hibernate auto update:
spring.jpa.hibernate.ddl-auto=update - JSP resolver:
- prefix:
/WEB-INF/views/ - suffix:
.jsp
- prefix:
When a user submits an order (POST /stocks/orderbook):
- Current session user is loaded.
- Timestamp string is generated.
- If user has enough funds, the order is saved and a trading history record is created.
- Balance update rules:
sell-> balance increases byprice * quantitybuy-> balance decreases byprice * quantity(only when funds check passes)
- Updated customer object is written back into session.
- Java 17
- MySQL running locally
- A
tradingdatabase created in MySQL
- Configure DB credentials in:
src/main/resources/application.properties
- Start the app:
cd <project-root>
./mvnw spring-boot:runWindows (PowerShell/CMD):
mvnw.cmd spring-boot:run- Open the app in browser:
http://localhost:8080/stocks
cd <project-root>
./mvnw test
./mvnw -DskipTests packageWindows (PowerShell/CMD):
mvnw.cmd test
mvnw.cmd -DskipTests package- Session state is central to navigation (
session_customer,session_stock). - Some classes/pages look like early/legacy scaffolding and are currently unused or partially used.
- The app currently uses Spring Boot 2.7.3 for compatibility with the existing codebase.