Home  >  Article  >  Database  >  How to effectively implement the addition, deletion, modification and query functions of mysql

How to effectively implement the addition, deletion, modification and query functions of mysql

无忌哥哥
无忌哥哥Original
2018-07-18 09:54:151733browse

1. Preface

Adding, modifying, deleting and querying data are the most commonly used functions in application software systems. As a software developer, it is very important to realize the above functions efficiently and ensure the correctness, standardization and validity of system data.

This article combines the add, delete, modify and check functions that I have completed in project practice, and analyzes and summarizes the development process and methods to implement the add, delete, modify and check functions, so as to better complete the development of similar functions in subsequent development work.

2. Development process and method

Added function

Added function is mainly to save the data items entered by the user on the page to the corresponding data table field in the data table .

The following steps can be used for analysis and implementation:

Based on business needs, what data items do users need to enter on the analysis page?

What data items need to be entered?

What are the entry methods (text box entry, drop-down list entry, checkbox entry, radio entry) and verification rules (non-null verification, field type, field length, field format) for each data item?

The corresponding relationship between input data items and data table fields (corresponding to which data table, which data field,)

Each data item on the page corresponds to which field of which data table?

Do the data item values ​​entered on the page need to be converted into database field values? (For example, convert the yes and no entered by the user on the page into database fields 1 and 0)

When saving data in the background, follow the following steps:

If the data verification is incorrect, then Prompt which data items are in incorrect format and how to fill them in the correct format.

If the save fails, the reason for the failure will be prompted to the user so that the user can save again after modification.

If the save is successful, the successful operation result will be fed back to the user.

If the save is abnormal, the user will be prompted that an exception occurred during the save operation, please try again.

If the VO data on the page only corresponds to one data table, just save it directly to one data table.

If the VO data of the page needs to be saved to multiple data tables in the database, a transaction management mechanism needs to be used to control the integrity of the data saving operation to prevent some tables from being saved successfully and some from failing to be saved.

If there are duplicate records, the duplicate information will be fed back to the user

If there are no duplicate records, perform the following saving steps.

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

Then, combined with the uniqueness rules of the data, Determine whether duplicate data records already exist;

Next, implement the conversion of page VO data items and persistent object PO: convert the VO data items entered by the user on the page into database entity objects, and call the corresponding Primary key generation rules generate primary key fields of database entity objects and other field values ​​that have nothing to do with the business but need to be saved in the database; perform the following save operation:

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

Delete function

The deletion function mainly deletes the data selected by the user from the database so that the data cannot be seen on the page.

The following methods can be used to analyze and implement:

Analyze the implementation method of deletion:

Should hard deletion (directly delete data from the database) or soft deletion ( Use the identification bit to identify that the data has been deleted)

Cascade data deleted hierarchically:

The data deleted by the operation on the page, whether there is record deletion: delete a piece of data in a data table , and delete the data records related to this record in another data table at the same time.

Analyze the operation method of deletion:

Delete according to which data item in the data record

Supports only one piece of data can be deleted at a time

Supports deleting multiple pieces of data at one time

Implementation method of deletion operation:

Obtain the primary key value of the data record that needs to be deleted in the background, and perform the deletion operation; if there is a cascade deletion In this case, after deleting the data record of the current table, you need to delete the data records related to the record in the related data table at the same time to ensure that there is no invalid redundant data in the database.

In the case of batch deletion, if one of the data is deleted incorrectly, the record will be written into the prompt message and the deletion of subsequent data records will continue;

Feedback the processing results of the deletion operation To the operating user:

If the deletion fails, the reason for the deletion failure will be fed back;

If the deletion is abnormal, the reason for the exception will be fed back and the user will be prompted to try again.

If the deletion is successful, a prompt message indicating that the operation is successful will be fed back to the user;

When viewing the data, the primary key of the data record will be hidden and displayed on the page,

When selecting When data is generated, the primary key corresponding to the selected data is saved.

When the user clicks the delete button, the user is first prompted to confirm the deletion. If the user chooses to confirm the deletion, the following processing steps are performed:

In After the deletion is successful, the displayed data on the page needs to be refreshed to display the deletion result (successfully deleted data is no longer displayed on the page) to the user.

Modification function

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

Query function

As mentioned in the overview, the development method of the Web layer is as follows:

Writing page VO: Analyze which data items need to be submitted by the Web display layer and which result data needs to be returned Item; uniformly encapsulate request data items and result data items into page VO. During coding implementation, the page VO class is an ordinary Bean class. It is enough to define data items and provide 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; convert the request data submitted by the VO into a data transmission object and transmit it to the Service layer for use; receive the service The processing result returned by the layer; convert the data transfer object returned by the processing result into the result data item of VO.

Write the Action configuration file:

Establish the request correspondence between the display layer request and the control layer: establish the relationship between the page request and the Action by configuring the Action information in the Action configuration file Correspondence.

Write the display layer page:

Use page VO to receive the user's request data: Set the form name in the page to be the same as the attribute name of the page VO to ensure that the page VO can receive the request data .

Set the Action address corresponding to the request: For the page button that submits the request, set the requested address to the Action address to ensure that the request can be submitted to the corresponding.

Receive the returned processing result: Receive the processing result returned by the request, and perform corresponding processing based on the processing result.

3. Summary

Based on the analysis of the main functions of the Web display layer and the Web control layer, this article conducts an in-depth analysis of the data interaction between the two, and proposes a proposal based on data interaction as the core It explains the development methods of the Web layer and summarizes the precautions for the development of the Web layer, which provides good reference and guidance for developing Web layer functions.

The above is the detailed content of How to effectively implement the addition, deletion, modification and query functions of mysql. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn