Bootstrap Table server implements paging effects

Implementing the Bootstrap Table server implementation paging DEMO, the specific content is as follows

Home index.html

                        Add event 
INDEX.JS
$ (Function () {// Initial Form INITTABLE (); // Search button Trigger Event $ ("# EventQuery"). Click () {$ ('# EventTable'). Bootstraptable (('refresh')); // is a very important step, refresh URL! // Console.log ("/ Program / Area / FindByItem? Offset =" + 0 + "&" + $ ("# areaform"). Serialize ()) $ ('# EventQueryform INPUT [Name = \ 'Name \'] '). VAL (') $ ('# EVENTQueryform INPUT [Name = \ 'SEQNO \'] '). VAL (' ')});}; // Table Initialization Function initTable () {$ (' # EventTable '). BootstrapTable ({Method:' POST ' , / / ​​To the server requesting: "Application / X-WWW-FORM-URLENCODED", // If it is POST, you must define the URL: '/ bootstrap_table_demo / findbyitem', // Request URL Cache: false, // Do you use a cache? , Default is True, so in general, you need to set this property (*) Striped: true, // Interlaced DataType: "json", // data type PAGINATION: TRUE, // Lookup SHOWPAGINATIONSWITCH: FALSE, // Whether to display the number of data: 10, // The number of records (*) PageList: [5, 10, 15, 20], // per page is displayed when the number of records (*) Pagenumber: 1, // Table is initialized. The number of rows (*) Search: false, // does not display SIDEPAGINATION: 'Server', // Services end paging classes: 'table Table-bordered', // Class style // showrefresh: true , // Display refresh button Silent: true, // must set refresh event ToolbaR: '#toolbar', // Toolbar ID Toolbaralign: 'Right', // Toolbar Align QueryParams: QueryParams, // Request Parameters, this relationship to subsequent refresh columns: [{Field: 'seqno ', Title:' Name, {Field: 'Name', Title: 'Name', Align: 'Center'}, {Field: 'SEX', TITLE: 'Gender', Align: 'Center'}, {Field: 'ID', Title: 'Operation', Align: 'Center', Width: '280px', Formatter: Function (Value, Row, INDEX) {// Console.log (Json.Stringify (}});}}],};} // Paging query parameters, Function QueryParams (params) {Return {Name: $ ('# {Name: $ (' # \ \ 'name) \ ']'). Val (), // Requires the parameters passing to the server seqno: $ ('# EventQueryform INPUT [Name = \' SEQNO \ ']'). Val (), Limit: params.limit, //The number of offset: params.offset, // sql statement offset}}


   / ** * Servlet implementation class * / public class UserFindByItemSetvlet extends HttpServlet {private static final long serialVersionUID = 1L; private IUserService service = new UserServiceImpl (); public UserFindByItemSetvlet () {super ();} protected void doGet (HttpServletRequest request , HttpServletResponse response) throws ServletException, IOException {this.doPost (request, response);} protected void doPost (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {request.setCharacterEncoding ( "utf-8"); response.setContentType ( " TEXT / JSON; Charset = UTF-8 "); // Get Form Data INT Offset = Integer.Parseint (RequesT.GetParameter ("offset"). Trim ()); int it = integer.Parseint ("limited"). Trim ()); string seqno = request.getParameter ("seqno"). Trim () String name = Request.getParameter ("name"). Trim (); // calls business components to get results PageBean 
PageBean; trybebean = service.FindByItem (Offset, Limit, SEQNO, Name); ObjectMapper Omapper = New ObjectMapper (); // Object Convert to JSON data, and return OMAPPER.WRITEVALUE (Response.Getwriter (), PageBean;} catch (exception e) {E.PrintStackTrace ();}}}

    / ** * Page entity class * / public class PageBean 
{/ ** royal truth class * / private list rows = new arraylist
(); / ** total number * / private INT TOTAL; public pagebean () {super ();} PublIC List

GetRows () {Return Rows;} public void set {this.rows = rows;} public int gettotal () {return total;} public void settotal (int Total) {THIS . Total = Total;}}

Obtaining a user to implement class
    Public class userServiceImpl imports iUserseervice {/ ** * SQL query statement * / public pagebean  FindByItem (int offset, int limit, string seqno, string name) {pagebean  cutbean = new pagebean  (); // Basic SQL statement string sql = "SELECT * From c_userinfo where 1 = 1 "; // Dynamic condition SQL statement string itemsql =" "; if (seqno! = Null && seqn.length ()! = 0) {itemsql + =" and seqno like '% "+ SEQNO + "% '";} if (name! = null && name.Length ()! = 0) {itemsql + = "And name Like '% "+ Name +"%' ";} // Get SQL Connection Connection Con = DBUTIL.CONNECT (); PreparedStatement PS = NULL; ResultSet RS = NULL; TRY {Ps = Con.PrepareStatement (SQL + ITEMSQL + "limit?,?"); ps.setint (1, offset); ps.setint (2, limit); rs = ps.executeQuery (); while (rs.next ()) {Userbean bean = new userbean ); bean.setseqno (RS.Getint ("seqno")); bean.setname (RS.GetString ("name")); bean.setSex (RS.Getint ("SEX")); bean.setbirth (RS.)); bean.setbirth GetString ("Birth")); cutbean.getrows (); add (bean);} // Get total record number, pay attention, also need to add dynamic conditions PS = con?preparestatement ("Select Count (*) AS C from C_UserInfo WHERE 1 = 1 "+ itemsql); rs = ps.executeQuery (); if (rs.next ()) {cutbean.settotal (rs.geTint ("c"));}} catch (sqlexception e) {E.PrintStackTrace ();} finally {dbutil.close (con); if (ps! = null) {Try {ps.close ();} catch (SQLEXCEPTION E) {E.PrintStackTrace ();}} f (rs! = Null) {Try {rc cclose ();} catch (sqlexception e) {E.PrintStackTrace ();}}} return cutbean;}}} return  

 / ** * Database tool class * * @Author way * * / public class DButil {/ ** * connected database * * / public static connection connect () {Properties pro = new Properties (); String driver = null; String url = null; String username = null; String password = null; try {InputSTream is = dbutil.class.getClassLoader () .getResourceAsStream ("db.properties"); Pro.Load (IS); driver = Pro.getProperty ("driver"); URL = Pro.GetProperty ("URL"); username = pro.getProperty ( "username"); password = pro.getProperty ( "password"); Class.forName (driver); Connection conn = DriverManager.getConnection (url, username, password); return conn;} catch (FileNotFoundException e ) {e.printStackTrace ();} catch (IOException e) {e.printStackTrace ();} catch (ClassNotFoundException e) {e.printStackTrace ();} catch (SQLException e) {e.printStackTrace ();} return null } / ** * Close Database * @Param Conn * * / Public Static Void Close (Connection Con) {if (con! = null) {Try {Con.close ();} catch (sqlexception e) {E.PrintStackTrace ();}}}      DB.Properties File 

DRIVER = com.mysql.jdbc.driverURL = JDBC: mysql: // localhost: 3306 / gov_social? Useunicode \ = true & characterencoding \ = UTF-8USERNAME = rootpassword = Root

The above is all the content of this article, I hope that everyone’s learning is helpful, I hope everyone will support Tumi Clouds.
                      
© Copyright Notice
THE END
Just support it if you like
like0
share
comment Grab the couch

Please log in to comment