How to effectively realize the function of adding and deleting MySQL

Source: Internet
Author: User

1. Preface

Adding, modifying, deleting and querying data is the most common function in application software system. As a software developer, how to achieve the above functions efficiently, and to ensure the correctness, standardization and effectiveness of the system data is very important.

This article unifies oneself in the project practice completes the deletion to change the function, the analysis and summarizes realizes the deletion to change the function development process and the method, in order to complete the similar function development in the subsequent development work better.

2. Development process and methodology

Add Features

The main function is to save the data items entered by the user on the page into the corresponding data table fields in the datasheet.

The following steps can be used to analyze and implement:

In combination with business needs, what data items does the user need to input on the analysis page?

What data items need to be entered?

What is the entry method for each data item (text box entry, drop-down list entry, CheckBox entry, radio entry) and validation rules (non-null check, field type, field length, field format)?

The corresponding relationship between data entry and table field (which data table, which data field,)

What field of data table does each item in the page correspond to?

Does the data item value of the page entry need to be converted to the value of the database field? (for example, the user input on the page and no conversion to database fields 1 and 0)

When saving data in the background, follow these steps:

If the data is not verified correctly, it indicates which data items are not properly formatted and how to fill in the correct format.

If the save fails, the cause of the failure is prompted to the user, which makes it easier for the user to modify and save again.

If the save succeeds, the result of the successful operation is fed back to the user.

If you save the exception, the user is prompted for an exception to the save operation, please try again.

If the VO data of the page corresponds to only one data table, it can be saved directly to a data table.

If the VO data of the page needs to be saved to multiple tables in the database, the transaction management mechanism should be used to control the integrity of the data preservation operation, prevent some tables from being saved successfully, and save the failed part.

If duplicate records already exist, they will be repeated feedback to the user

If there are no duplicate records, the following save steps are performed.

First, you need to receive page entry data items, then verify the validity and validity of the data items (type, length), and

Then, combined with the uniqueness of the data rules, determine whether there is already duplicate data records;

Then, the transformation of the page VO data item and the persisted object PO: Convert the VO data item entered on the page into the database entity object, and invoke the corresponding primary key generation rule, generate the primary key field of the database entity object and other business-independent, but need to save the field value in the database ; Perform the following save operation:

Finally, the results of the processing of the save operation are fed back to the user:

Remove Features

The deletion function mainly deletes the user's selected data from the database and realizes that the data is not visible on the page.

The following methods can be used to analyze and implement:

To parse the delete implementation:

Hard Delete (delete data directly from the database) or soft delete (identifying data with identity bits has been deleted)

Cascading data for hierarchical deletion:

Operations on the page delete data, whether there is a record deletion: Delete one data table data, while the other data table in relation to the records related to the record deleted simultaneously.

How to parse the delete operation:

Which data item is deleted according to the data record

Support for deleting only one piece of data at a time

Support to delete multiple data at once

How to implement the delete operation:

The background gets the primary key value of the data record that needs to be deleted, performs the delete operation, and if there is a cascade delete, it is necessary to delete the data record of the current table and the data record related to that record in the related data table, to ensure that there is no invalid redundant data in the database.

In the case of bulk deletion, if one of the data is deleted, the record is written to the prompt and the subsequent data record is deleted;

Feedback the processing result of the delete operation to the operation User:

If the deletion fails, then feedback to the cause of the deletion failure;

If the exception is removed, the reason for the feedback exception prompts the user to retry.

If the deletion is successful, the feedback operation is successful and the user is prompted.

When you view the data, hide the primary key of the data record on the page,

When selecting data, save the primary key corresponding to the selected data.

When the user clicks the Delete button, first prompts the user to confirm the deletion, if the user chooses to confirm the deletion, performs the following processing steps:

After the deletion succeeds, the display data on the page needs to be refreshed, and the result of the deletion (the deletion of successful data is not displayed on the page) is presented to the user.

modifying features

The modification function is primarily to re-edit the data items already in the database and save the modified data to the database.

Query function

As described in the review, the Web layer is developed as follows:

Write page VO: Analyze what data items the Web display layer needs to submit, what result data items need to be returned, and uniformly encapsulate the request data item and the result data item to page VO. When encoding is implemented, the page Vo class is a normal bean class, which defines the data items and provides the set and get methods.

Write the control layer action: Define the page Vo object, use the page Vo object to receive the request data submitted by the Web display layer, and convert the request data submitted by VO to the data transfer object, transfer it to the service layer, and receive the processing result returned by the service layer. ; Converts the data transfer object returned by the processing result to a result data item of VO.

To write the action configuration file:

Establish the request correspondence between the display layer request and the control layer by configuring the action information in the action's configuration file to establish the correspondence between the page request and the action.

To write a display layer page:

Use page VO to receive the user's request data: Sets the form name on the page to be the same as the page Vo's property name, guaranteeing that the page Vo can receive the request data.

Set the action address of the request: for the page button for the submit request, set the requested address to the action address, ensuring that the request can be submitted to the corresponding.

Receive the returned processing result: receives the request to return the processing result, according to the processing result carries on the corresponding processing.

3. Summary

Based on the analysis of the main functions of Web display layer and Web control layer, this paper analyzes the data interaction between the two, and puts forward the development method of Web layer with the data interaction as the core, and summarizes the considerations of Web layer development, which has good reference and guidance to the development of Web layer function.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.