Fading Coder

One Final Commit for the Last Sprint

Home > Tech > Content

Java-Based E-Commerce Platform for Mobile Devices: Architecture and Implementation

Tech 1

Technical Architecture

Backend Framework: Spring Boot

Spring Boot is an open-source framework designed for rapid development of applications based on the Spring framework. It follows the convention over configuration principle, providing default configurations that allow developers to focus on business logic rather than configuration files. Through automated configuration and convention-based approaches, Spring Boot significantly simplifies application configuration. Developers no longer need to manually configure numerous XML files or complex annotations, as the framework provides default configurations that automatically complete setup based on project dependencies and conventions. Spring Boot utilizes Maven or Gradle for building, automatically downloads project dependencies, and offers various plugins to streamline the build process. Developers can use Spring Initializr to generate a basic project structure and then select required dependencies as needed.

Frontend Framework: Vue.js

Vue.js is designed with the goal of being as simple, easy to understand, and approachable as possible. Vue provides an intuitive API that enables developers to build interactive user interfaces effortlessly. Vue.js offers a simple yet powerful data binding mechanism, allowing for two-way binding between views and data through directives like v-model. When data changes, the view updates automatically, and vice versa, eliminating the need for manual DOM manipulation. Vue.js provides a set of lifecycle hook functions that allow developers to execute custom logic at different stages of a component's lifecycle, including creation, mounting, updating, and destruction, offering greater flexibility.

Feasibility Analysis

Feasibility analysis is an essential part of any project development, as it can directly impact the viability of a system. This analysis evaluates whether the developed system can address the shortcomings of traditional manual processing methods and better solve existing problems in the library management system. Through the development and design of this library management system, we can gradually reduce the workload of staff while enabling more efficient work and management. Therefore, the development of this system achieves maximum significance and value. After system completion, it's crucial to analyze whether the benefits outweigh the costs and whether the expected results can be achieved. The following aspects were considered in the feasibility analysis of this system:

  • Technical Feasibility: The adoption of Java technology makes this system design feasible due to the maturity of the technology.
  • Economic Feasibility: Whether the benefits after system completion outweigh the development costs.
  • Operational Feasibility: The design focuses on user-friendliness and practicality.

System Testing

The primary objective of system testing is to identify issues from multiple perspectives. Through functional testing, we aim to discover and correct system defects, ensuring the system is free of errors. During testing, we verify that the system meets client requirements and promptly address any identified problems and shortcomings. After completing testing, we draw test conclusions.

Purpose of System Testing

System testing is an indispensable yet patience-testing process. Its importance lies in being the final checkpoint ensuring system quality and reliability, as well as the last inspection in the entire system development process. System testing primarily aims to prevent user issues during operation and enhance user experience. To avoid affecting user experience, we need to consider potential problems from multiple angles and perspectives, simulating different scenarios to identify and resolve defects. The testing process also helps us understand the system's quality, the completeness of its functions, and the smoothness of its logic. A thorough system testing process significantly improves system quality and user experience. The goal is to verify whether the system meets the requirements defined in the specification document and identify any discrepancies or conflicts with the requirements.

Functional Testing

Functional testing involves testing system modules through various methods such as clicking, inputting boundary values, and validating required and optional fields. We perform black-box testing by writing test cases and executing them according to their content, ultimately drawing test conclusions.

Login Function Test Cases

Input Data Expected Result Actual Result Analysis
Username: admin, Password: 123456, Captcha: Correct Login successful System login successful Matches expected result
Username: admin, Password: wrongpass, Captcha: Correct Password error Password error, please retry Matches expected result
Username: admin, Password: 123456, Captcha: Incorrect Captcha error Captcha information error Matches expected result
Username: empty, Password: 123456, Captcha: Correct Username required Please enter username Matches expected result
Username: admin, Password: empty, Captcha: Correct Password error Password error, please retry Matches expected result

User Management Function Test Cases

Input Data Expected Result Actual Result Analysis
Enter user basic information Addition successful, user appears in list User appears in the list Matches expected result
Modify user information Update successful, information modified User information modified Matches expected result
Select and delete user System asks for confirmation, user deleted after confirmation System asks for confirmation, user not found after deletion Matches expected result
Add user without username 提示用户名不能为空 (Username cannot be empty) 提示用户名不能为空 (Username cannot be empty) Matches expected result
Enter existing username Addition failed, username duplicate error Addition failed, username duplicate error Matches expected result

Database Design

Column Name Data Type Length Constraints
id int 11 PRIMARY KEY
addtime timestamp - DEFAULT CURRENT_TIMESTAMP
order_number varchar 64 DEFAULT NULL
product_code varchar 64 DEFAULT NULL
product_name varchar 12 DEFAULT NULL
payment_description varchar 64 DEFAULT NULL
payment_amount decimal 10,2 DEFAULT NULL
payment_date date - DEFAULT NULL
customer_name varchar 64 DEFAULT NULL
phone_number varchar 64 DEFAULT NULL

Code Implementation

/**
 * Common API Controller
 */
@RestController
@RequestMapping("/api/common")
public class CommonApiController {
    
    @Autowired
    private CommonService commonService;
    
    @Autowired
    private ConfigurationService configService;
    
    private static BaiduFaceClient faceClient = null;
    
    private static String BAIDU_MAP_API_KEY = null;
    
    @GetMapping("/location")
    public ResponseEntity<Map<String, Object>> getLocation(@RequestParam String longitude, @RequestParam String latitude) {
        if(BAIDU_MAP_API_KEY == null) {
            BAIDU_MAP_API_KEY = configService.getValueByName("baidu_map_api_key");
            if(BAIDU_MAP_API_KEY == null) {
                return ResponseEntity.badRequest().body(Map.of("error", "Please configure baidu_map_api_key in settings"));
            }
        }
        Map<String, String> locationData = BaiduLocationUtil.getCityByCoordinates(BAIDU_MAP_API_KEY, longitude, latitude);
        return ResponseEntity.ok(Map.of("data", locationData));
    }
    
    /**
     * Face recognition comparison
     * 
     * @param image1 First face image
     * @param image2 Second face image
     * @return Comparison result
     */
    @PostMapping("/compare-faces")
    public ResponseEntity<Map<String, Object>> compareFaces(@RequestParam String image1, @RequestParam String image2) {
        if(faceClient == null) {
            String apiKey = configService.getValueByName("baidu_api_key");
            String secretKey = configService.getValueByName("baidu_secret_key");
            String authToken = BaiduAuthUtil.getAccessToken(apiKey, secretKey);
            if(authToken == null) {
                return ResponseEntity.badRequest().body(Map.of("error", "Please configure API key and secret key correctly"));
            }
            faceClient = new BaiduFaceClient(null, apiKey, secretKey);
            faceClient.setConnectionTimeout(2000);
            faceClient.setReadTimeout(60000);
        }
        
        JSONObject comparisonResult = null;
        try {
            File file1 = new File(ResourceUtils.getFile("classpath:uploads").getAbsolutePath() + "/" + image1);
            File file2 = new File(ResourceUtils.getFile("classpath:uploads").getAbsolutePath() + "/" + image2);
            
            String base64Image1 = Base64Converter.encodeImageToBase64(file1);
            String base64Image2 = Base64Converter.encodeImageToBase64(file2);
            
            FaceComparisonRequest request1 = new FaceComparisonRequest(base64Image1, "BASE64");
            FaceComparisonRequest request2 = new FaceComparisonRequest(base64Image2, "BASE64");
            
            List<FaceComparisonRequest> requests = Arrays.asList(request1, request2);
            comparisonResult = faceClient.compareFaces(requests);
            
            System.out.println(comparisonResult.get("result"));
        } catch (FileNotFoundException e) {
            return ResponseEntity.badRequest().body(Map.of("error", "File not found"));
        } catch (IOException e) {
            return ResponseEntity.internalServerError().body(Map.of("error", "Processing error"));
        }
        
        return ResponseEntity.ok(Map.of("data", JSON.parseObject(comparisonResult.get("result").toString())));
    }
}

Database Schema

-- User table
CREATE TABLE `users` (
  `id` bigint NOT NULL AUTO_INCREMENT COMMENT 'Primary key',
  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Creation time',
  `username` varchar(200) NOT NULL COMMENT 'Username',
  `password` varchar(200) NOT NULL COMMENT 'Password',
  `full_name` varchar(200) DEFAULT NULL COMMENT 'Full name',
  `gender` varchar(200) DEFAULT NULL COMMENT 'Gender',
  `avatar` varchar(200) DEFAULT NULL COMMENT 'Avatar',
  `phone` varchar(200) DEFAULT NULL COMMENT 'Phone',
  `id_card` varchar(200) DEFAULT NULL COMMENT 'ID card',
  PRIMARY KEY (`id`),
  UNIQUE KEY `username` (`username`)
) ENGINE=InnoDB AUTO_INCREMENT=1616222324596 DEFAULT CHARSET=utf8mb3 COMMENT='User information';

-- Messages table
CREATE TABLE `messages` (
  `id` bigint NOT NULL AUTO_INCREMENT COMMENT 'Primary key',
  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Creation time',
  `user_id` bigint NOT NULL COMMENT 'User ID',
  `username` varchar(200) DEFAULT NULL COMMENT 'Username',
  `content` longtext NOT NULL COMMENT 'Message content',
  `reply` longtext COMMENT 'Reply content',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1616222424131 DEFAULT CHARSET=utf8mb3 COMMENT='Message board';

-- Authentication token table
CREATE TABLE `auth_tokens` (
  `id` bigint NOT NULL AUTO_INCREMENT COMMENT 'Primary key',
  `user_id` bigint NOT NULL COMMENT 'User ID',
  `username` varchar(100) NOT NULL COMMENT 'Username',
  `table_name` varchar(100) DEFAULT NULL COMMENT 'Table name',
  `role` varchar(100) DEFAULT NULL COMMENT 'Role',
  `token` varchar(200) NOT NULL COMMENT 'Token',
  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Creation time',
  `expires_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Expiration time',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb3 COMMENT='Authentication token table';

Related Articles

Understanding Strong and Weak References in Java

Strong References Strong reference are the most prevalent type of object referencing in Java. When an object has a strong reference pointing to it, the garbage collector will not reclaim its memory. F...

Comprehensive Guide to SSTI Explained with Payload Bypass Techniques

Introduction Server-Side Template Injection (SSTI) is a vulnerability in web applications where user input is improper handled within the template engine and executed on the server. This exploit can r...

Implement Image Upload Functionality for Django Integrated TinyMCE Editor

Django’s Admin panel is highly user-friendly, and pairing it with TinyMCE, an effective rich text editor, simplifies content management significantly. Combining the two is particular useful for bloggi...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.