First Assignment_832401223_Wu_JunJia

832401223吴浚嘉 832401223吴浚嘉 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区

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.

 

...全文

相关推荐

asp友情链接交换平台系统

asp友情链接交换平台系统友情链接管理

XIN3218

高校技术转移办公室人员如何推动科技成果的精准对接?.docx

高校技术转移办公室人员如何推动科技成果的精准对接?

BIZKEEN

高校技术转移办公室人员如何利用平台提升成果转化对接效率?.docx

高校技术转移办公室人员如何利用平台提升成果转化对接效率?

BIZKEEN

产业园区运营负责人如何利用数智工具精准匹配企业技术需求?.docx

产业园区运营负责人如何利用数智工具精准匹配企业技术需求?

BIZKEEN

通信行业基于RocketMQ事务消息的最终一致性实现:计费场景下本地事务与消息投递的工程化协同方案

内容概要:本文深入探讨了RocketMQ事务消息在通信行业核心场景中的工程化应用,重点解决本地事务与消息发送之间的一致性难题。通过“半消息+两阶段提交+状态回查”机制,RocketMQ确保计费、开通、停复机等关键操作在本地数据库事务成功后,消息必定可靠投递,从而实现最终一致性。文章结合Spring Boot与RocketMQTemplate的代码实例,详细解析了事务消息的生产者实现、本地事务执行与状态回查的协同逻辑,并强调消费端幂等设计的重要性。随着RocketMQ 5.x在高可用与轻量化方向的发展,事务消息正从应用层补偿手段演进为支撑5G、实时计费等场景的通信级一致性基础设施。; 适合人群:具备Java与Spring Boot开发经验,熟悉消息队列基本概念,从事通信、金融或高一致性要求系统开发的中高级研发人员;尤其适用于关注分布式事务、最终一致性与系统可靠性的工程师。; 使用场景及目标:①掌握RocketMQ事务消息在计费、账单同步等场景中的落地实践;②理解半消息、本地事务对齐、状态回查等核心机制的设计原理与编码要点;③构建具备强一致性保障的分布式通信系统,减少对人工对账与定时补偿的依赖; 阅读建议:本文结合实际代码与行业场景,建议读者在理解原理的基础上,动手搭建环境并调试事务消息全流程,重点关注本地事务与数据库交互的原子性、回查逻辑的持久化依赖以及消费端的幂等处理,以全面掌握其在高可靠系统中的最佳实践。

matlab@com
评论
收藏 已收藏
分享
返回顶部