First Assignment_832401223_Wu_JunJia

832401223吴浚嘉 2026-10-03 21:43:58

First Assignment: FrontEnd and BackEnd Separation Calculator System

Submitter: Wu JunJia
FZU ID: 832401223
MU ID: 24125181


Table of Contents

  • 1. Assignment Overview
  • 2. Project Design
  • 3. Project Implementation Description
  • 4. PSP Table
  • 5. Project Demo Materials
  • 6. GitHub Repository and Code Standards
  • 7. Project Summary

1. Assignment Overview

The objective of this assignment is to build a web calculator system with a "separated frontend and backend architecture". The calculator supports multi-term four arithmetic operations. All calculation history is persistently saved in the backend H2 database. Each record includes record ID, expression, result, device information and complete timestamp. The frontend web page handles UI interaction independently. The SpringBoot backend provides RESTful APIs. Frontend and backend communicate with each other via JSON over HTTP.


2. Project Design

2.1 System Architecture

The project uses a separated frontend-backend architecture:

1. Frontend : Static HTML + CSS + JavaScript web page, placed in SpringBoot static resource folder. Responsible for page rendering and button interaction. It sends JSON requests through `fetch` to the backend and receives returned results.

2. Backend : SpringBoot framework with layered structure: Controller → Service → Entity → Repository.

3. Database : H2 file-based database for persistent storage. Data will not be lost after restarting the application.

Architecture Diagram:

Browser Frontend <--HTTP & JSON--> SpringBoot Backend API <--> H2 Database

 

2.2 Database Table Design

Table name: calc_history

Field NameTypeDescription
idLongAuto-increment record ID
expressionStringCalculation expression input by user
resultStringCalculation result
device_infoStringClient browser / device information
create_timeLocalDateTimeCalculation timestamp

 

2.3 API Design

MethodEndpointRequest BodyResponseFunction
POST/api/calc{expr:"1+2", deviceInfo:"xxx"}{"result":"3"}Calculate expression and save history record
GET/api/history-List of history recordsQuery all calculation history
DELETE/api/history-{"msg":"Cleared"}Delete all history records

 

2.4 Calculator Interaction Logic

1. After calculation completes, the result "will NOT be cleared automatically". The result stays on the input box.

2. After finishing a calculation:

    - Press "number button" : Start a brand-new expression and discard the old result.

    - Press "operator (+ - * /)" : Use the previous result as the left operand to continue calculation.

3. If there is no expression OR the calculation is already finished, clicking the equal button will do nothing, and no new history record will be created.


3. Project Implementation Description

3.1 Development Environment

- JDK: 21

- Framework: Spring Boot 3.2.0

- Database: H2 Database 

- Build Tool: Maven

- Frontend: HTML, CSS, Vanilla JavaScript

- Version Control: Git + GitHub

 

3.2 Development Workflow

1. "Requirement Analysis" : Analyze assignment requirements, define calculator interaction rules, database fields and the boundary between frontend and backend.

2. "System Design" : Design layered backend structure, database tables, REST APIs and frontend state flag `isCalculated`.

3. "Backend Coding" :

    - Create entity class, Repository and Controller;

    - Implement Reverse Polish Notation algorithm in Service layer to parse mathematical expressions;

    - Configure H2 file database to enable data persistence.

4. "Frontend Coding" : Build web UI, implement button logic, add `isCalculated` state flag, send requests to backend and load history records.

5. "Test & Debug" : Test four arithmetic operations and edge cases (division by zero, repeated equal clicks), fix interaction bugs.

6. "Deployment & Verification" : Launch SpringBoot locally, access web page from browser and verify all functions.

7. "Accessibility Test" : Use Chrome Lighthouse to test web accessibility and optimize HTML ARIA attributes.

8. "Documentation" : Write README, create independent English code standard documents for frontend and backend, push source code to GitHub.

 

3.3 Problems and Solutions

1. "Problem" : Newer JDK removed Nashorn script engine. `eval()` cannot be used to evaluate expressions directly.

> "Solution": Implement Reverse Polish Notation algorithm to parse expressions manually on backend, without script engine.

2. "Problem" : H2 uses in-memory mode by default, all history data is lost after application shutdown.

> "Solution" : Modify `application.yml` configuration and switch to file storage mode for persistent data.

3. "Problem" : The interaction logic of equal button, number buttons and operator buttons does not meet requirements.

> "Solution" : Add `isCalculated` state flag to control button behavior after calculation completes.


4. PSP Table

PhaseEstimated Time (minutes)Actual Time (minutes)
Requirement analysis1518
System design3034
Front-end development180192
Back-end development180147
Expression parser150135
Database design6023
History module9076
Front-end and back-end integration7541
Testing120115
Deployment4548
Blog writing6089
Other work4522

5. Project Demo Materials

Project directory structure screenshot

GitHub repository homepage screenshot (contains two English code standard files)

Calculator web interface screenshot


6. GitHub Repository and Code Standards


7. Project Summary

This project implements a web calculator with separated frontend and backend, fulfilling all required interaction functions and database persistence. During development, I learned SpringBoot layered development, REST API design and H2 database configuration. I also practiced Git version control, code standards and web accessibility testing. The project strictly follows the idea of frontend-backend separation. Frontend and backend have separate responsibilities to reduce coupling.

 

...全文
45 回复 打赏 收藏 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复
内容概要:本文介绍了“Java+大数据+AI架构师实战营”这一系统性人才培养方案,旨在帮助具备Java基础的开发者在26周内完成向融合Java、大数据与人工智能技术的复合型架构师跃迁。课程围绕五大核心模块展开:架构基本功(微服务演进、分布式锁与ID设计)、数据引擎(亿级数据存储与Flink CDC实时同步)、网关与可观测性(Gateway源码改造、限流与日志采样)、AI融入架构(推荐系统、大模型应用开发)以及架构思维培养。通过“小绿书”项目贯穿始终,强调整合三域技术的系统设计能力而非孤立技能堆叠。; 适合人群:具备1-5年Java开发经验,希望突破技术瓶颈、拓展大数据与AI领域能力的中高级研发人员;适合有志于成长为全栈架构师的技术从业者。; 使用场景及目标:①掌握高并发、分布式系统下的架构设计方法;②理解海量数据的存储分层与实时计算架构;③学会将AI能力如大模型、RAG、向量检索等深度集成到业务系统中;④构建完整的系统可观测性与网关控制能力;⑤形成跨技术域的系统性架构思维。; 阅读建议:此资源以实战项目驱动学习,强调动手实践与架构思维并重。建议学习者结合课程代码与实际调试,深入理解每一环节的技术选型与设计权衡,尤其关注真实生产环境中难以复现的复杂约束,从而建立可迁移的架构“手感”。

173

社区成员

发帖
与我相关
我的任务
社区描述
梅努斯-软件工程
软件工程 高校 福建省·福州市
社区管理员
  • FZU_SE_LQF
  • zjcTander
  • 木村修
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧