MVC architecture mode with JavaBean paging! (Original)

zhaozj2021-02-16  56

It is well known that MVC is not a design mode, a larger mode than the design mode, called the design pattern is unreasonable, the MVC mode should be called architecture mode, and there are many small modes in MVC, such as policy mode, combination mode, aggregation mode, There are more than a dozen models, while the design mode is 27, MVC is important, and now popular Struts frameworks are also similar implementation. It is recommended that you have time to study Struts, now many companies have started using This framework is for large enterprise system development, Struts is an open source project of Apache, and all materials can be obtained from the Apache website. Of course, there are also translated Struts articles in China, but most of them are incomplete, introducing them are primary knowledge. If you want to learn more, you can buy this Struts book.

MVC is also a model - view - console, m is JavaBean, v is JSP, c is Java servlet.

First step by writing the HashTable class, write all classes to the JSP file path into here

The second step is to write the most abstract interface interface, give a method, for example

Public Void Execute (HTTPSERVLET Servlet, HTTPSERVLETREQUEST, HTTPSERVLETRESPONSE);

All servlet classes that interact with the client must implement the Execute method of this interface, so that it can be implemented in the factory.

The third step writing console, in fact, this I think is a higher factory model of the factory model.

Perform the corresponding class according to the action

Web.xml file can be configured, this must be familiar, for example

servlet_name

servlet_class_path

servlet_name

mapped

It is convenient for a lot. No need to add each of each class plus in the XML file. Moreover, it is more convenient to increase the modification of the later function.

Using the JavaBean page is actually very simple, but if you want to write the structure, you need 3 classes, a bean class, a process page, etc., one get the client value, I will give an example below, if there is If you don't understand, please keep it.

Simple Bean class

Package Geezer_Model.geezer_user;

Public class Listuser_bean {

String name; String Pass;

Public void setname (String name) {

THIS.NAME = Name;

}

Public void setpass (string pass) {

THIS.PASS = Pass;

}

Public string getname () {

Return this.name;

}

Public string getpass () {

Return this.pass;

}

}

Simple class with paging data

Package Geezer_Model.geezer_user;

Import javax.sql. *;

Import java.sql. *;

Import geezer_controller. *;

Import Geezer_Database.getConnection;

Public class listuser_page {

Public Listuser_page () {

}

Connection conn = NULL;

Statement SIMT = NULL;

ResultSet RS = NULL;

INT INTPAGE = 1;

INT INTPAGECUNT = 10;

INT PageCount = 20;

INT Page_ListCount = 1;

String SQL;

Public Listuser_Bean [] getPage (int INTPAGE, INT INTPAGECUNT, STRING SQL) {

THIS.INTPAGE = INTPAGE;

THIS.INTPAGECUNT = INTPAGECOUNT;

THIS.SQL = SQL;

Listuser_bean [] TMIE = NULL;

Try {

CONN = getConnection.getnewConnection ();

SIMT = conn.createstatement ();

RS = Simt.executeQuery (this.sql);

IF (rs.next ()) {

Rs.last ();

PageCount = rs.getrow ();

Page_listcount = (pageCount INTPAGECOUNT-1) / INTPAGECOUNT;

IF (INTPAGE> Page_ListCount) {

INTPAGE = Page_ListCount;

}

INT PageWo = (INTPAGE-1) * INTPAGECUNT 1;

IF (PageWo> 0) {

Rs.absolute (PageWo);

}

TMIE = New Listuser_bean [INTPAGECOUNT];

INT i = 0;

Do {

TMIE = New Listuser_bean ();

Tmie.SetPass ("Password"); TMIE.setName (Rs.getstring ("UserName"));} while (rs.next () && i 转载请注明原文地址:https://www.9cbs.com/read-19559.html


New Post(0)