五月天青色头像情侣网名,国产亚洲av片在线观看18女人,黑人巨茎大战俄罗斯美女,扒下她的小内裤打屁股

歡迎光臨散文網(wǎng) 會(huì)員登陸 & 注冊(cè)

struts2框架:分頁查詢,easyui實(shí)現(xiàn)管理模塊,查詢數(shù)據(jù)庫(kù)條數(shù),視頻筆記【詩(shī)書畫唱】

2021-01-13 23:51 作者:詩(shī)書畫唱  | 我要投稿

CTRL+F:關(guān)于查詢到數(shù)據(jù)庫(kù)條數(shù)的方法。視頻和視頻筆記。


附加的話:這期的學(xué)習(xí)內(nèi)容比較簡(jiǎn)單,所以一些視頻筆記這類的沒記錄太多。關(guān)于查詢到數(shù)據(jù)庫(kù)條數(shù)的方法。

代碼例子 START

package com.SSHC.action;


import java.io.ByteArrayInputStream;

import java.io.InputStream;

import java.io.UnsupportedEncodingException;

import java.util.ArrayList;

import java.util.HashMap;

import java.util.List;

import java.util.Map;


import com.SSHC.bean.Game;

import com.SSHC.dao.GameDao;


public class GameAction {

private Map<String,Object>map = new HashMap<String,Object>();

? ? private GameDao gameDao = new GameDao();

? ? private Game g;

? ? //添加分頁屬性

? ? private Integer rows;//每頁記錄條數(shù)

? ? private Integer page;//頁碼數(shù)

public Map<String, Object> getMap() {

return map;

}


public void setMap(Map<String, Object> map) {

this.map = map;

}

public GameDao getGameDao() {

return gameDao;

}


public void setGameDao(GameDao gameDao) {

this.gameDao = gameDao;

}


public Integer getRows() {

return rows;

}


public void setRows(Integer rows) {

this.rows = rows;

}


public Integer getPage() {

return page;

}


public void setPage(Integer page) {

this.page = page;

}


public Game getG() {

return g;

}


public void setG(Game g) {

this.g = g;

}


public String loadAll(){

System.out.println("每頁顯示" + rows + "條數(shù)據(jù)");

System.out.println("當(dāng)前顯示第" + page + "頁的數(shù)據(jù)");

g = new Game();

g.setPage(page);

g.setRows(rows);

List<Game>list = gameDao.selectByPage(g);

Integer total = gameDao.total();

map.put("rows", list);

map.put("total", total);

return "success";

}

}


package com.SSHC.bean;


public class Game {

? ? private Integer id;

? ? private String gname;

? ? private String gtype;

? ? private String gcomp;

? ? private String gyear;

? ??

? ? //分頁屬性

? ? private Integer page;

? ? private Integer rows;

public Integer getId() {

return id;

}

public void setId(Integer id) {

this.id = id;

}

public String getGname() {

return gname;

}

public void setGname(String gname) {

this.gname = gname;

}

public String getGtype() {

return gtype;

}

public void setGtype(String gtype) {

this.gtype = gtype;

}

public String getgcomp() {

return gcomp;

}

public void setgcomp(String gcomp) {

this.gcomp = gcomp;

}

public String getGyear() {

return gyear;

}

public void setGyear(String gyear) {

this.gyear = gyear;

}

public Integer getPage() {

return page;

}

public void setPage(Integer page) {

this.page = page;

}

public Integer getRows() {

return rows;

}

public void setRows(Integer rows) {

this.rows = rows;

}

}

package com.SSHC.dao;


import java.sql.Connection;

import java.sql.PreparedStatement;

import java.sql.ResultSet;

import java.sql.SQLException;

import java.util.ArrayList;

import java.util.List;


import com.SSHC.bean.Game;

import com.SSHC.util.DbUtil;


public class GameDao {

? ? public List<Game>selectByPage(Game game){

? ? String sql = "select * from game limit ?,?";

? ? List<Game>list = new ArrayList<Game>();

? ? Connection conn = null;

? ? PreparedStatement pstm = null;

? ? ResultSet rs = null;

? ?

? ? try {

? ? ? ? conn = DbUtil.getConn();

pstm = conn.prepareStatement(sql);

Integer page = game.getPage();

Integer rows = game.getRows();

//隱藏的記錄條數(shù)

Integer hideCount = (page - 1) * rows;

pstm.setInt(1, hideCount);

pstm.setInt(2, rows);

rs = pstm .executeQuery();

while(rs.next()){

Game g = new Game();

g.setId(rs.getInt("id"));

g.setGname(rs.getString("gname"));

g.setGtype(rs.getString("gtype"));

g.setgcomp(rs.getString("gcomp"));

g.setGyear(rs.getString("gyear"));

list.add(g);

}

} catch (SQLException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} finally {

DbUtil.close(rs, pstm, conn);

}

? ? return list;

? ? }

? ??

? ? public Integer total(){

? ? String sql = "select count(*) ct from game";

? ? Integer count = 0;

? ? Connection conn = null;

? ? PreparedStatement pstm = null;

? ? ResultSet rs = null;

? ?

? ? try {

? ? ? ? conn = DbUtil.getConn();

pstm = conn.prepareStatement(sql);

rs = pstm.executeQuery();

if(rs.next()) {

count = rs.getInt("ct");



System.out.println("count:"+count);

}

} catch (SQLException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} finally {

DbUtil.close(rs, pstm, conn);

}? ?

? ? return count;

? ? }

}

package com.SSHC.util;


import java.io.IOException;

import java.io.InputStream;

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.PreparedStatement;

import java.sql.ResultSet;

import java.util.Properties;


public class DbUtil {

private static String driverName;

? ? private static String url;

? ? private static String user;

? ? private static String pwd;

? ??

? ? static {

? ? //讀取properties文件

? ? Properties prop = new Properties();

? ? //將db.properties文件讀取到內(nèi)存中去

? ? InputStream is = DbUtil.class.getClassLoader()

? ? .getResourceAsStream("db.properties");

? ? //加載內(nèi)容

? ? try {

prop.load(is);

//讀取內(nèi)容

driverName = prop.getProperty("drivername");

url = prop.getProperty("url");

user = prop.getProperty("username");

pwd = prop.getProperty("password");

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

? ? }

? ??

? ? //獲取數(shù)據(jù)庫(kù)連接對(duì)象的方法

? ? public static Connection getConn(){

? ? Connection conn = null;

? ? try {

Class.forName(driverName);

conn = DriverManager.getConnection(url,user,pwd);

} catch (Exception e) {

// TODO Auto-generated catch block

e.printStackTrace();

}? ?

? ? return conn;

? ? }

? ??

? ? public static void close(ResultSet rs,PreparedStatement pstm

? ? ,Connection conn){

? ? ? ? try {

? ? ? ? if(rs != null) {

? ? ? ? ? ? rs.close();

? ? ? ? ? ? }

? ? ? ? ? ? if(pstm != null) {

? ? ? ? ? ? pstm.close();

? ? ? ? ? ? }

? ? ? ? ? ? if(conn != null) {

? ? ? ? ? ? conn.close();

? ? ? ? ? ? }

? ? ? ? } catch(Exception e) {

? ? ? ? e.printStackTrace();

? ? ? ? }

? ? }

}

drivername=com.mysql.jdbc.Driver

url=jdbc:mysql://localhost:3306/firstjsp?useUnicode=true&amp;characterEncoding=GBK2312

username=root

password=root


<?xml version="1.0" encoding="UTF-8" ?>

<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">

<struts>

? ? ?<package name="my" namespace="/gm" extends="json-default">

? ? ? ? ?<action name="ldAc" class="com.SSHC.action.GameAction"

? ? ? ? ? ? ?method="loadData">

? ? ? ? ? ? ?<result type="stream">

? ? ? ? ? ? ? ? ?<param name="contentType">text/plain</param>

? ? ? ? ? ? ? ? ?<!-- action返回的字符串的內(nèi)容取自GameAction的哪個(gè)屬性 -->

? ? ? ? ? ? ? ? ?<param name="inputName">ins</param>

? ? ? ? ? ? ?</result>

? ? ? ? ?</action>

? ? ? ? ?<action name="ldAllAc" class="com.SSHC.action.GameAction"

? ? ? ? ? ? ?method="loadAll">

? ? ? ? ? ? ?<result type="json">

? ? ? ? ? ? ? ? ?<param name="root">map</param>

? ? ? ? ? ? ? ? ?<param name="contentType">text/html</param>

? ? ? ? ? ? ?</result>

? ? ? ? ?</action>??

? ? ?</package>

</struts>



<?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">

? <display-name>EasyuiJavaWebHomeWork1</display-name>

? <!-- struts2框架的配置 -->

? <filter>

? ? ? <filter-name>struts2</filter-name>

? ? ? <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>

? </filter>

? <filter-mapping>

? ? ? <filter-name>struts2</filter-name>

? ? ? <url-pattern>/*</url-pattern>

? </filter-mapping>

? <welcome-file-list>

? ? <welcome-file>index.html</welcome-file>

? ? <welcome-file>index.htm</welcome-file>

? ? <welcome-file>index.jsp</welcome-file>

? ? <welcome-file>default.html</welcome-file>

? ? <welcome-file>default.htm</welcome-file>

? ? <welcome-file>default.jsp</welcome-file>

? </welcome-file-list>

</web-app>

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>

<%

? ? String path = request.getContextPath();

? ? String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

? ? <head>

? ? ? ? <base hreff="<%=basePath%>">

? ? ? ? <title></title>

? ? ? ? <meta http-equiv="pragma" content="no-cache">

? ? ? ? <meta http-equiv="cache-control" content="no-cache">

? ? ? ? <meta http-equiv="expires" content="0">

? ? ? ? <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">

? ? ? ? <meta http-equiv="description" content="This is my page">

? ? </head>

? ? <body>

? ? ? ? <h1 align="center">新增游戲</h1>

? ? ? ? <form action="" method="post">

? ? ? ? ? ? <table align="center">

? ? ? ? ? ? ? ? <tr>

? ? ? ? ? ? ? ? ? ? <td>游戲名稱:</td>

? ? ? ? ? ? ? ? ? ? <td>

? ? ? ? ? ? ? ? ? ? ? ? <input name="gname" class="easyui-validatebox"?

? ? ? ? ? ? ? ? ? ? ? ? ? ? data-options="required:true"?

? ? ? ? ? ? ? ? ? ? ? ? ? ? validType="length[6,30]"?

? ? ? ? ? ? ? ? ? ? ? ? ? ? invalidMessage="游戲名稱的長(zhǎng)度必須在6到30位之間"

? ? ? ? ? ? ? ? ? ? ? ? ? ? style="width:180px;" />

? ? ? ? ? ? ? ? ? ? </td>

? ? ? ? ? ? ? ? </tr>

? ? ? ? ? ? ? ? <tr>

? ? ? ? ? ? ? ? ? ? <td>游戲類型:</td>

? ? ? ? ? ? ? ? ? ? <td>

? ? ? ? ? ? ? ? ? ? ? ? <input name="gtype" class="easyui-combobox"

? ? ? ? ? ? ? ? ? ? ? ? ? ? style="width:180px;"

? ? ? ? ? ? ? ? ? ? ? ? ? ? data-options="valueField:'id',textField:'gtype',

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? panelHeight:'auto',editable:false,data:[{

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? id:'1',

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? gtype:'塔防'

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? },{

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? id:'2',

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? gtype:'戰(zhàn)略'

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? },{

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? id:'3',

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? gtype:'MOB'

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? },{

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? id:'4',

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? gtype:'RPG'

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? },{

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?id:'5',

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?gtype:'休閑'

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? }]" />

? ? ? ? ? ? ? ? ? ? </td>

? ? ? ? ? ? ? ? </tr>

? ? ? ? ? ? ? ? <tr>

? ? ? ? ? ? ? ? ? ? <td>游戲公司:</td>

? ? ? ? ? ? ? ? ? ? <td>

? ? ? ? ? ? ? ? ? ? ? ? <input name="gcomp" class="easyui-validatebox"??

? ? ? ? ? ? ? ? ? ? ? ? ? ? validType="length[4,30]"?

? ? ? ? ? ? ? ? ? ? ? ? ? ? invalidMessage="游戲公司的長(zhǎng)度必須在4到30位之間"

? ? ? ? ? ? ? ? ? ? ? ? ? ? style="width:180px;" />

? ? ? ? ? ? ? ? ? ? </td>

? ? ? ? ? ? ? ? </tr>

? ? ? ? ? ? ? ? <tr>

? ? ? ? ? ? ? ? ? ? <td>游戲年份:</td>

? ? ? ? ? ? ? ? ? ? <td>

? ? ? ? ? ? ? ? ? ? ? ? <input name="gyear" class="easyui-numberbox"

? ? ? ? ? ? ? ? ? ? ? ? ? ? data-options="min:1000,max:9999"

? ? ? ? ? ? ? ? ? ? ? ? ? ? style="width:180px;" />

? ? ? ? ? ? ? ? ? ? </td>

? ? ? ? ? ? ? ? </tr>

? ? ? ? ? ? ? ? <tr>

? ? ? ? ? ? ? ? ? ? <td colspan="2" align="center">

? ? ? ? ? ? ? ? ? ? ? ? <a hreff="javascript:void(0);" class="easyui-linkbutton"

? ? ? ? ? ? ? ? ? ? ? ? ? ? data-options="iconCls:'icon-save'">保存</a>

? ? ? ? ? ? ? ? ? ? ? ? <a hreff="javascript:clsWin();" onclick="clsWin();" class="easyui-linkbutton"

? ? ? ? ? ? ? ? ? ? ? ? ? ? data-options="iconCls:'icon-cut'">取消</a>

? ? ? ? ? ? ? ? ? ? </td>

? ? ? ? ? ? ? ? </tr>

? ? ? ? ? ? </table>

? ? ? ? </form>

? ? </body>

</html>





————

{"total":2,"rows":[{"id":1,"gname":"WANGZHERONGYI","gtype":"MOB","gcomp":"TENCENT","gyear":2010}]}

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>

<%

? ? String path = request.getContextPath();

? ? String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

? ? <head>

? ? ? ? <base hreff="<%=basePath%>">

? ? ? ? <title></title>

? ? ? ? <meta http-equiv="pragma" content="no-cache">

? ? ? ? <meta http-equiv="cache-control" content="no-cache">

? ? ? ? <meta http-equiv="expires" content="0">

? ? ? ? <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">

? ? ? ? <meta http-equiv="description" content="This is my page">

? ? </head>

? ? <body>

? ? ? ? <h1>修改</h1>

? ? </body>

</html>

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>

<%

? ? String path = request.getContextPath();

? ? String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

? ? <head>

? ? ? ? <base hreff="<%=basePath%>">

? ? ? ? <title></title>

? ? ? ? <meta http-equiv="pragma" content="no-cache">

? ? ? ? <meta http-equiv="cache-control" content="no-cache">

? ? ? ? <meta http-equiv="expires" content="0">

? ? ? ? <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">

? ? ? ? <meta http-equiv="description" content="This is my page">

? ? ? ? <link rel="stylesheet" type="text/css" hreff="css/themes/default/easyui.css">

? ? ? ? <link rel="stylesheet" type="text/css" hreff="css/themes/icon.css">

? ? ? ? <script type="text/javascript" srcc="js/jquery.min.js"></script>

? ? ? ? <script type="text/javascript" srcc="js/jquery.easyui.min.js"></script>

? ? ? ? <!-- 語言漢化包 -->

? ? ? ? <script type="text/javascript" srcc="js/locale/easyui-lang-zh_CN.js"></script>

? ? ? ? <script type="text/javascript">

? ? ? ? ? ? function toAdd(){

? ? ? ? ? ? var url = 'add.jsp';

? ? $('#win').window({

? ? width : 700,//寬度

? ? height : 550,//高度

? ? title : '新增',

? ? href : url

? ? });

? ? $('#win').window('open');//打開窗體

? ? ? ? ? ? }

? ? ? ? ? ??

? ? ? ? ? ? function toEdit(){

? ? ? ? ? ? //獲取選中的行

? ? ? ? ? ? var row = $('#dg').datagrid('getSelected');

? ? ? ? ? ? //判斷是否選中

? ? ? ? ? ? if(! row) {

? ? ? ? ? ? $.messager.alert("提示", "請(qǐng)選要修改的數(shù)據(jù)", "info");

? ? ? ? ? ? } else {

? ? ? ? ? ? var url = 'edit.jsp';

? ? ? ? $('#win').window({

? ? ? ? width : 700,//寬度

? ? ? ? height : 550,//高度

? ? ? ? title : '修改',

? ? ? ? href : url

? ? ? ? });

? ? ? ? $('#win').window('open');//打開窗體

? ? ? ? ? ? }

? ? ? ? ? ? }

? ? ? ? ? ??

? ? ? ? ? ? function doDelete(){

? ? ? ? ? ? //獲取選中的行

? ? ? ? ? ? var row = $('#dg').datagrid('getSelected');

? ? ? ? ? ? //判斷是否選中

? ? ? ? ? ? if(! row) {

? ? ? ? ? ? $.messager.alert("提示", "請(qǐng)選要?jiǎng)h除的數(shù)據(jù)", "info");

? ? ? ? ? ? } else {

? ? ? ? ? ? ? ? //實(shí)現(xiàn)刪除功能

? ? ? ? ? ? }

? ? ? ? ? ? }

? ? ? ? ? ??

? ? ? ? ? ? function clsWin(){

? ? ? ? ? ? $('#win').window('close');

? ? ? ? ? ? }

? ? ? ? </script>

? ? </head>

? ? <body>

? ? ? ? <table id="dg" class="easyui-datagrid" title="游戲管理模塊"?

? ? ? ? ? ? style="width:1000px;height:450px"

data-options="singleSelect:true,collapsible:true,

url:'gm/ldAllAc.action',method:'get',pagination:true,

pageList:[3,5,7,10,15],pageSize:5,toolbar:'#tb'">

<thead>

<tr>

<th data-options="field:'id',width:80">游戲ID</th>

<th data-options="field:'gname',width:100">游戲名稱</th>

<th data-options="field:'gtype',width:80,align:'right'">游戲類型</th>

<th data-options="field:'gcomp',width:80,align:'right'">游戲公司</th>

<th data-options="field:'gyear',width:250">游戲年份</th>

</tr>

</thead>

</table>

<!-- 工具欄 -->

<div id="tb" style="padding:5px;height:auto">

? ? <div style="margin-bottom:5px">

? ? ? ? <a hreff="javascript:toAdd();" onclick="toAdd();" class="easyui-linkbutton"?

? ? ? ? ? ? iconCls="icon-add" plain="true" title="新增"></a>

<a hreff="javascript:toEdit();" onclick="toEdit();" class="easyui-linkbutton"?

? ? iconCls="icon-edit" plain="true" title="修改"></a>

<a hreff="javascript:doDelete();" onclick="doDelete();" class="easyui-linkbutton"?

? ? iconCls="icon-remove" plain="true" title="刪除"></a>

? ? </div>

</div>

<!-- 彈出窗體 -->

<div id="win" class="easyui-window"

data-options="modal:true,closed:true,iconCls:'icon-save', top: 20,

? ? minimizable: false,maximizable: false,collapsible: false,left: 100">

? ? </div>??

? ? </body>

</html>

運(yùn)行后:




代碼例子 END


視頻和視頻筆記 START



以下效果在eclipse中容易卡,進(jìn)而看起來像是沒效果,但在QQ瀏覽器中比較有效果:



關(guān)于查詢到數(shù)據(jù)庫(kù)條數(shù)的方法 START


關(guān)于查詢到數(shù)據(jù)庫(kù)條數(shù)的方法 END









視頻和視頻筆記 END




struts2框架:分頁查詢,easyui實(shí)現(xiàn)管理模塊,查詢數(shù)據(jù)庫(kù)條數(shù),視頻筆記【詩(shī)書畫唱】的評(píng)論 (共 條)

分享到微博請(qǐng)遵守國(guó)家法律
惠州市| 泽普县| 霸州市| 齐齐哈尔市| 丁青县| 宕昌县| 靖远县| 台东市| 师宗县| 白水县| 清镇市| 定安县| 泌阳县| 锡林浩特市| 瓮安县| 张家界市| 黔东| 工布江达县| 乡城县| 湖南省| 金坛市| 玉环县| 枞阳县| 宁德市| 江陵县| 廊坊市| 南京市| 长岭县| 大方县| 江山市| 南汇区| 利辛县| 乌拉特中旗| 六盘水市| 滨州市| 青龙| 沂源县| 镇赉县| 林甸县| 察隅县| 阿荣旗|