MM.MYSQL MYSQL JDBC Driver (MVC)

xiaoxiao2021-03-06  59

MM.MYSQL MYSQL JDBC driver

I: Introduction to remember JSP, I always like to compare him and ASP, PHP, and I used to use ASP development model to write JSP later, I found this is really stupid. In fact, JSP has been used out. MVC mode. Below I briefly say that JSP design uses MVC to design. II: MVC introduction MVC is actually moderate, view, controlled abbreviation, that is, when using JSP, there is a corresponding file to implement the corresponding operation. Usually JSP is only responsible for the view is only responsible for displaying the page. BEAN (EJB) is implemented in business logic. The discussed below is achieved without using EJB. If you use EJB, EJB is responsible for M.c usually by servlet. Or use struts.struts to introduce you to http://jakarta.apache.org/struts to see. I will introduce in later articles. Three: Design Thoughts When you build an Application. You must consider the problem of interface, and interface modification is very common. If you implement all your operations in JSP, you have trouble in the modification interface. The art does not understand JSP, you must go to revise countless files, don't be too big, and at this time, you will be very tight, you can reduce your troubles. JSP is only responsible for displaying the page at the design, that is, the JSP calls the data passed by the bean (Struts, servlet) and then the bean (struts, servlet) is responsible for collecting the data required by JSP, transmitting the ARRAYLIST (ArtTIBUTE) to JSP. If you need to submit a form, it is generally directly submitted to the struts, servlet, and then returns the processing information later. And the corresponding business logic is implemented by bean. Four: Bean's design When I use, Bean usually has three types, below the Manager, Entry, and Database directory. The bean under Manager as the commercial logic entry is packaged data, in fact, every database table corresponds to a bean. All JSP is all class. The bean under Database is the operational database, performs such as Insert, Update, Delete, Load (query a record), BatchLoad (Query multiple records). The relationship between them is entry responsible for packaging data, as a calling parameters of Database, returns the result. Manager calls the result of the Database processing. Manager and JSP communications. The results obtained from JSP come from Manager, JSP needs to do operation calling Manager, even an insert has such a method in Database but in Manager, you still need to package it once. The purpose of this is to make the structure as simple as possible. Database is only responsible for operating the database.

Manager is only logically (take the appropriate data) to handle the corresponding logic, and the entry only takes the data package taken by Database, or encapsulates the parameter to the page, as a parameter passed to the corresponding bean. 5: Design instance I discuss the message board as an example: entry / guestbook.java (Message object) Database / GuestbookMap.java (Update, Remove, Modify Message Board) Manager / GuestbookManager.java (Processing All Transactions) Data Table Structure (PostgreSQL) Create Sequence Seq_Guestbook Increment 1; / ** Serial number generator ** / create table guestbook (ID INT8 Default NextVal ('seq_guestbook'), / ** Primon ** / Title Varchar (64), / ** Topic ** / Body text, / ** content ** / sayid int8, / ** spokesman ** / toid int8, / ** acceptor ** / saytime datetime default now (), / ** message time ** / newflg Smallint Default 1 / ** Whether you view ** /); guestbook.java ============================================================================================================================================================================================================================================ {private int id; private String title; private body title; private int sayid; private int sayid; private Date saytime; private short newflg; public Guestbook () {} public int getId () {return this.id;} public void setId (int _id) {this.id = _id;} ........ (all get / set method)} guestbookmap.java ================== ============ Import guestbook; public class guestbookmap () {public guestbook () {} public guestbook load (int id) {// Take a GUE stbook} // sqlstr query // orderstr sorted // rcdbegin recording start // rcdend recording end // public ArrayList batchLoad (String sqlstr, String orderstr, int rcdbegin, int rcdend) {// ArrayList which encapsulates Guestbook} public void insert (Guestbook info) {} public void update (Guestbook info) {} public void delete (int id) {// get to a guestbook} public int getRcdNums (String sqlstr) {// get the number of records}} GuestbookManager. Java is the method you want to write according to the needs of the package, this part is what you want to write =======================================================================================================================================

============= The above way Entry, Database file can be automatically generated, I have developed this tool, if you need to contact me. What you need to write is the method in GuestBookManager. You may feel that the workload is big in JSP than all your operations, but this structure is very clear. You still need to write a database connection pool, all your database operations are taken from one place, and each time you go to connect to the database overhead. Six: Technical advantages 1: Clear structure 2: Maintenance is convenient 3: Protection code is better. ........ seven: Conclusion, I just briefly introduce, the specific use you need to accumulate in practical use, if you need my code to see, contact me, if you think you wrote and the shit, Very embarrassed, wasting your precious time. http://ijsp.net/2/2002-6/18/000092.SHTML

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

New Post(0)