JSPbean mysql database newly modified universal method

xiaoxiao2021-03-06  39

Due to the convenient and fast database characteristics of JavaBeans, see another article. Make us convenient to record the database to add editing and deletion modifications. The preparation of this feature can be completely automated, that is, design a database, for this database The JSP code for the new editing delete function can be automatically prepared. It is now analyzed as follows:

1. Create a database xxx:

Need to guarantee a primary key

Create Table XXX (ID INT (20) Not Null Auto_Increment, record name record name 2 ........ primary key (id))

2. Established bean assumptions to xxx.java

// SET Data Sheet Record Name // Get Data Sheet Record Name // This is the predetermined write method of bean, visible to my article data bean automatic assignment private int ID = 0; public void setid (int ID) {this.id = ID;} public int getId () {return;} private string record name = 0; public void set record name (String record name) {this. Record name = record name;} public string get record name () {Return Record Name;} .... // Recommended with Replace instead of INSERT and UPDATE I / / Implement the database XXX in the Replace method // such as Replace INTP XXX (ID, record name, ..) VALUES (?,? , ..) PUBLIC VOID Replace () throws Exception {.....} public void delete () throws exception {.....} public void selete () throws exception {.....}

3. Join the process control in XXX.JSP:

// The following sentence guarantees that the data in the JSP form automatically enters the ..... <% IF (Request.GetParameter (" Save ") // Call the Replace method in the bean XXX.Replace () Else if (Request.GetParameter (" DEL ")) // Call DELETE method XXX.delete () else {%> // Displays the form

<% if (= SAVE value = ON> IF Request.GetParameter ("Edit")! = null) {// If it is an edit database to display the corresponding data value to xxx.select ();%> <%}%> > > ....... <%}%>

4. Call:

New features: xxx.jsp editing features: xxx.jsp? Edit = on & id = xxx delete function: xxx.jsp? Del = on & id = xxx summary:

As long as you know the structure of the database, JavaBean / JSP can automatically come out for this database through the form, some are just cumbersome, this process is actually fully allowed to execute, just tell this program your database structure, record Name, record type (int String or FLOAT type), the program automatically outputs a set of JSP / bean code programs. This set of code programs are used to add new editing to the database.

In our daily development, as long as there is a database, there is a function of adding a new editor of the database, using this idea, you can easily done. 2002/03/01

转载请注明原文地址:https://www.9cbs.com/read-68947.html

New Post(0)