The first is DataObject, the project is SPRINGMVC
public class Mbchannelextensiondo {private static final long serialversionuid = 741231858441822688L; ========== Properties ==========/** * This property corresponds to DB column <tt>id</tt>. */private String id;/** * This property corresponds to DB column <tt>bank_name</tt>. */private String bankname;/** * This property corresponds to DB column <tt>product_type</tt>. */private String producttype;/** * This property corresponds to DB column <tt>exchange_type</tt>. */private String exchangetype;/** * This property corresponds to DB column <tt>sign_verify_ele</tt>. */private String signverifyele;/** * This property corresponds to DB column <tt>channel_id</tt>. */private String channelid;/** * This property corresponds to DB column <tt>gmt_create</tt>. */private Date gmtcreate;/** * This property corresponds to DB column <tt>creator</tt>. */private String creator;/** * This property coRresponds to DB column <tt>gmt_modified</tt>. */private Date gmtmodified;/** * This property corresponds to DB column <tt>updator</tt>. */private String updator;/** * This property corresponds to DB column <tt>status</tt>. */private String status; ========== getters and Setters ==========/** * Getter method for property <tt>id</tt>. * * @return property value of ID */public String getId () {return ID;} /** * Setter method for property <tt>id</tt>. * * @param ID value to being assigned to property id */public void setId (String id) {this.id = ID;} /** * Getter method for property <tt>bank_name</tt>. * * @return Property value of Bankname */public String getbankname () {return bankname;} /** * Setter method for property <tt>bank_name</tt>. * * @param bankname value to being assigned to property bankname */public void Setbankname (String bankname) {This.bankna me =Bankname;} /** * Getter method for property <tt>product_type</tt>. * * @return Property value of ProductType */public String Getproducttype () {return producttype;} /** * Setter method for property <tt>product_type</tt>. * * @param producttype value to being assigned to property ProductType */public void Setproducttype (String producttype) {this.producttype = ProductType;} /** * Getter method for property <tt>sign_verify_ele</tt>. * * @return Property value of Signverifyele */public String Getsignverifyele () {return signverifyele;} /** * Setter method for property <tt>sign_verify_ele</tt>. * * @param signverifyele value to being assigned to property Signverifyele */public void Setsignverifyele (String Signverifyel E) {this.signverifyele = Signverifyele;} /** * Getter method for property <tt>exchange_type</tt>. * * @return Property value of Signverifyele */public String Getexchangetype () { return exchangetype; }/** * Setter method for property <tt>exchange_type</tt>. * * @param exchangetype value to being assigned to property ExchangeType */public void Setexchangetype (String exc Hangetype) {this.exchangetype = ExchangeType;} /** * Getter method for property <tt>channelid</tt>. * * @return Property value of Channelid */public String getchannelid () {return channelid;} /** * Setter method for property <tt>channelid</tt>. * * @param channelid value to being assigned to property channelid */public void Setchannelid (String channelid) {this.ch Annelid = Channelid;} /** * Getter method for property <tt>gmtcreate</tt>. * * @return Property value of Gmtcreate */public Date getgmtcreate () {return gmtcreate;} /** * Setter method for property <tt>gmtcreate</tt>. * * @param gmtcreate value to being assigned to property gmtcreate */public void Setgmtcreate (Date gmtcreate) {this.gmtcreate = gmtcreate;} /** * Getter method for property <tt>creator</tt>. * * @return Property value of creator */public String Getcreator () {return creator;} /** * Setter method for property <tt>creator</tt>. * * @param creator value to being assigned to property creator */public void Setcreator (String creator) {this.creator = Creator;} /** * Getter method for property <tt>gmtmodified</tt>. * * @return Property value of Gmtmodified */public Date getgmtmodified () {return gmtmodified;} /** * Setter method for property <tt>gmtmodified</tt>. * * @param gmtmodified value to being assigned to property gmtmodified */public void Setgmtmodified (Date gmtmodified) {T his.gmtmodified = gmtmodified;} /** * Getter method for property <tt>updator</tt>. * * @return Property value of Updator */public String Getupdator () {return updator;} /** * Setter method for properTy <tt>updator</tt>. * * @param updator value to being assigned to property updator */public void Setupdator (String updator) {this.updator = Updator;} /** * Getter method for property <tt>status</tt>. * * @return property value of status */public String GetStatus () {return status;} /** * Setter method for property <tt>status</tt>. * * @param status value to being assigned to property status */public void SetStatus (String status) {This.status = Statu s;}
Next is the page class that uses pagination
public class Pagedo {/** * total number of bars */private int totalnumber; /** * Current Page */private int currentpage; /** * Total pages * */private int totalpage; /** * Number of bars per page */private int pagenumber = 10; /** * Calculates and sets the value of the relevant property based on the value of the property in the current object */public void count () {//Calculate total number of pages int totalpagetemp = This.totalnumber /This.pagenumber; int plus = (this.totalnumber% this.pagenumber) = = 0? 0:1; Totalpagetemp = Totalpagetemp + Plus; if (totalpagetemp <= 0) {totalpagetemp = 1; } this.totalpage = Totalpagetemp; Set current page//Total page less than current page, the current page should be set to total number of pages if (This.totalpage < this.currentpage) {this.currentpage = This.totalpage; }//The current page is less than 1 set to 1 if (This.currentpage < 1) {this.currentpage = 1; }} public int gettotalnumber () {return totalnumber; } public void Settotalnumber (int totalnumber) {This.totaLnumber = Totalnumber; This.count (); } public int Getcurrentpage () {return currentpage; } public void Setcurrentpage (int currentpage) {this.currentpage = CurrentPage; } public int Gettotalpage () {return totalpage; } public void Settotalpage (int totalpage) {this.totalpage = Totalpage; } public int Getpagenumber () {return pagenumber; } public void Setpagenumber (int pagenumber) {this.pagenumber = pagenumber; This.count (); }}
Two ways to implement paging in a DAO layer
/** * Select <tt>MbChannelExtensionDO</tt> object by page to DB table <tt>mb_channel_extension< ;/tt>, return primary KEY * * <p> * The SQL statement for this operation is <br> * <t T>select * from mb_channel_extension where ID not in (SELECT ID from Mb_channel_extension * where rownum<= (PAGES ize* (CURRENTPAGE-1))) and rownum<=pagesize order by ID; </tt> * * @param page,mbchannelextension * @return list<mbchannelextensiondo> * @throws dataacces Sexception */@Override public list<mbchannelextensiondo> getmbchannelextensionbypage (Mbchannelextensiondo Mbchannelextensiondo,pagedo page) throws DataAccessException {if (page = = null) {throw new Illegalarg Umentexception ("Can ' t select by a null page."); } Map map=new HashMap (); Map.put ("page", page); Map.put ("Mbchannelextension", Mbchannelextensiondo); Return GetsqlmapclienttemplAte (). queryForList ("Ms-mb-channel-extension-select-by-page", map); } @Override public int countofmbchannelextension (Mbchannelextensiondo mbchannelextensiondo) throws Dataaccessexcept ion {int count= (Integer) getsqlmapclienttemplate (). queryForObject ("Ms-mb-channel-extension-count", Mbchannelextensiondo); return count; }
The following is a mapping file for MyBatis
</pre><pre name= "code" class= "HTML" style= "FONT-SIZE:11.8181819915771PX;" ><select id= "Ms-mb-channel-extension-select-by-page" parameterclass= "Java.util.Map" resultmap= " Rm-mb-channel-extension "> select * from Mb_channel_extension where ID not in (SELECT ID from mb_channel_extension where 1=1 and RowNum <! [Cdata[<=]]> (#page. pagenumber#* (#page. currentpage#-1))) <dynamic> <isnotempty prepend= "and" property= "Mbchannelextension.bankname" > Bank_name= #mbChannelExtension. bankname# </isNotEmpty> <isnotempty prepend= "and" property= "M Bchannelextension.producttype "> Product_type= #mbChannelExtension. producttype# </isnotempty > <isnotempty prepend= "and" property= "Mbchannelextension.exchangetype" > Exchange_type= #mbChan nelextension.exchangetype# </isNotEmpty> </dynamic> and RowNum <! [cdata[<=]]> #page. pagenumber# ORDER by ID </select> <select id= "Ms-mb-channel-ext Ension-count "resultclass=" Java.lang.Integer "> select COUNT (ID) from Mb_channel_extension W Here 1=1 <dynamic> <isnotempty prepend= "and" property= "Bankname" > bank_name=# bankname# </isNotEmpty> <isnotempty prepend= "and" property= "ProductType" > Product_type= #productType # </isNotEmpty> <isnotempty prepend= "and" property= "ExchangeType" > exchange_type= #exchangeType # </isNotEmpty> </dynamic><p> </s elect></p><div></div>
Here is the controller layer
@RequestMapping ("/channlextension") public String Selectcustomer (mbchannelextensiondo Customer,pagedo page, HttpServletRequest Request) { if (page==null) { page=new Pagedo (); Page.setpagenumber (1); Page.count (); } Mbchannelextensiondo channelextension = new Mbchannelextensiondo (); channelextension = customer; Page.settotalnumber (Channelextensionservice.countofmbchannelextension (Customer)); This.tcustomerlist = This.channelExtensionService.getMbChannelExtensionByPage (customer,page); Request.setattribute ("Tcustomerlist", tcustomerlist); Request.setattribute ("page", page); Request.setattribute ("Channelextension", channelextension); return "/channlextension/channlextension"; }
Front-end HTML and JS
<form name = "frm" id= "mainform" method= "post" action= "<%=request.getcontextpath ()%>/channlextension.html" > <div class= ' page fix ' style= "text-align:end;margin:5px 30px 20px 30px;" > Total <b>${page.totalNumber}</b> Strip <c:if test= "${page.currentpage! = 1}" > <a href= "Javascript:changecurrentpage (' 1 ')" class= ' first ' > Home </a> <a href= "Javascript:changecurrentpage (' ${page.currentpage-1} ')" class= ' pre ' > prev </a> </c:if> Current section <span>${page.currentPage}/${page.totalPage}</span> page <c:if test= "${page.curren Tpage! = page.totalpage} "> <a href=" javascript:changecurrentpage (' ${page.currentpage+1} ') "class= ' Next ' > next page </a> <a href= "Javascript:changecurrentpage (' ${page.totalpage} ')" Class= ' last ' > End </a> </c:if> Skip to &nbsP;<input id= "Currentpagetext" name= "currentpage" type= ' text ' value= ' ${page.currentpage} ' class= ' AllInput w28 '/ > page <a href= "Javascript:changecurrentpage ($ (' #currentPageText '). Val ())" class= ' Go ' >go&l t;/a> </div></form><script type= "Text/javascript" > Function changecurrentpage (currentPa GE) {$ ("#currentPageText"). Val (currentpage); $ ("#mainForm"). Submit (); }</script>
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Java Paging implementation