您的位置:首页 > 编程语言 > Java开发

JavaWeb之高级分页查询

2017-08-13 16:28 399 查看
分页的原理:

**假分页/逻辑分页/内存 分页: 一次性把所有数据全部查询出来存放到内存中,每次翻页都从内存中去截取指定数量的数据.

优点:每次翻页比较快,简单; 缺点:若数据过大,可能造成内存溢出问题.

真分页/物理分页/数据库分页: 每次翻页的时候都从数据库中取出指定数量的数据(MySQL: LIMIT ?,?语句).

优点:若数据过大,不会造成内存溢出问题; 缺点:复杂,每次翻页较慢.**

所以一般我们需要进行分页,肯定是每次翻页的时候去数据库中取出指定数量数据再按照每页的数据数量进行分页.LIMIT?,?语句

1):查询符合条件的结果集.
SELECT * FROM 表名 [WHERE 条件1 AND 条件2] [ORDER BY .....] LIMIT ?,?;
第一个?:当前页从哪一个索引开始截取数据:start/begin/beginIndex(从0开始).
beginIndex = (currentPage - 1) * pageSize;
第二个?:截取多少条数据:pageSize;
2):查询符合条件的结果总数.
SELECT COUNT(*) FROM 表名 [WHERE 条件1 AND 条件2];


高级分页查询的本质就是多条件筛选

而对其操作的实质就是拼SQL的查询条件.

SELECT * FROM 表名 WHERE 条件1 AND 条件2 ….

以下不多说直接附上代码,进行一个高级分页查询

和商品的CRUD操作的综合Demo.

domian层

package com._jerry._domain;

import java.math.BigDecimal;

import lombok.Data;

@Data
public class Product {
private String productName;
private Long id;
private BigDecimal salePrice;
private BigDecimal costPrice;
private Double cutoff;
private String supplier;
private String brand;
//封装分类对象
private ProductDir productDir;
}


package com._jerry._domain;

import lombok.Data;

@Data
public class ProductDir {
private Long id;
private String dirName;
private Long parent_id;
}


DAO层

package com._jerry._Interface;

import com._jerry._domain.Product;
import com._jerry._result.PageResult;

public interface IproductDAO {

//  List<Product> query(IQuery qo);

/**
* 对象集合查询结果
* @return
*/
PageResult pageQuery(IQuery qo, String tableName);

/**
* 定义CRUD的操作  除了查询操作意外
*/
Product get(Long id);

void delete(Long id);

int update(Product newProduct);

void save(Product product);

}


package com._jerry._Interface;

import java.util.List;

import com._jerry._domain.ProductDir;

public interface IProductDirDAO {
List<ProductDir> dirs();
}


package com._jerry._implement;

import java.util.List;
import com._jerry._Interface.IQuery;
import com._jerry._Interface.IResultSetHandler;
import com._jerry._Interface.IproductDAO;
import com._jerry._domain.Product;
import com._jerry._jdbcTemplate.JdbcTemplate;
import com._jerry._result.PageResult;
import com._jerry._result.ResultSetHandler;
import com._jerry._util.QueryUtil;

@SuppressWarnings("all")
public class ProductDAOImpl implements IproductDAO {
private IResultSetHandler<List<Product>> rsh = new ResultSetHandler();
/*public List<Product> query(IQuery qo) {
String sql = "SELECT * FROM product"+qo.getQuery();
return JdbcTemplate.query(sql, rsh,qo.getParameters().toArray());
}*/

//高级查询和分页查询综合方法
public PageResult pageQuery(IQuery qo, String tableName) {
PageResult pageResult = QueryUtil.doQuery(qo, tableName, rsh);
return pageResult;
}

//crud操作
public void delete(Long id) {
String sql = "DELETE  FROM product WHERE id = ?";
JdbcTemplate.upDate(sql, id);
}

public int update(Product newProduct) {
String sql = "UPDATE product SET productName=?,dir_id=?,salePrice=?," +
"supplier=?,brand=?,cutoff=?,costPrice=? WHERE id = ?";
Object[] params = { newProduct.getProductName(),
newProduct.getProductDir().getId(), newProduct.getSalePrice(),
newProduct.getSupplier(), newProduct.getBrand(),
newProduct.getCutoff(), newProduct.getCostPrice(),
newProduct.getId() };
int num = JdbcTemplate.upDate(sql, params);
return num;
}

public void save(Product obj) {
String sql = "INS
4000
ERT INTO product (productName,dir_id,salePrice,supplier,brand,"
+ "cutoff,costPrice) VALUES(?,?,?,?,?,?,?)";
Object[] params = { obj.getProductName(), obj.getProductDir().getId(),
obj.getSalePrice(), obj.getSupplier(), obj.getBrand(),
obj.getCutoff(), obj.getCostPrice() };
JdbcTemplate.upDate(sql, params);
}

public Product get(Long id) {
//用来做更新操作的时候 取出指定id的对象
String sql = "SELECT * FROM product WHERE id = ?";
List<Product> product = JdbcTemplate.query(sql, rsh, id);
return product.size() == 1 ? product.get(0):null;
}

}


package com._jerry._implement;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com._jerry._Interface.IProductDirDAO;
import com._jerry._Interface.IResultSetHandler;
import com._jerry._domain.ProductDir;
import com._jerry._jdbcTemplate.JdbcTemplate;

public class ProductDirDAOImpl implements IProductDirDAO{
private IResultSetHandler<List<ProductDir>> rsh = new ProductDirResultHandler();
public ProductDir getDir(Long id){
String sql = "SELECT * FROM productdir WHERE id = ?";
List<ProductDir> list = JdbcTemplate.query(sql, rsh, id);
if (list != null) {
return list.get(0);
}
return null;

}
public List<ProductDir> dirs() {
String sql = "SELECT * FROM productdir";
List<ProductDir> list = JdbcTemplate.query(sql, new ProductDirResultHandler());
return list;
}
class ProductDirResultHandler implements IResultSetHandler<List<ProductDir>>{

public List<ProductDir> handler(ResultSet rs) throws SQLException {
List<ProductDir> list = new ArrayList<>();
while (rs.next()) {
ProductDir productDir = new ProductDir();
list.add(productDir);
productDir.setId(rs.getLong("id"));
productDir.setDirName(rs.getString("dirName"));
productDir.setParent_id(rs.getLong("parent_id"));
}
return list;
}

}
}


service层

package com._jerry._servlet;

import java.io.IOException;
import java.math.BigDecimal;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com._jerry._Interface.IProductDirDAO;
import com._jerry._Interface.IproductDAO;
import com._jerry._domain.Product;
import com._jerry._domain.ProductDir;
import com._jerry._implement.ProductDAOImpl;
import com._jerry._implement.ProductDirDAOImpl;
import com._jerry._implement.ProductQueryObject;
import com._jerry._result.PageResult;
import com._jerry._util.StringUtil;

@WebServlet("/query")
@SuppressWarnings("all")
public class QueryServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
private IproductDAO dao;
private IProductDirDAO dirDAO;

public void init() throws ServletException {
dao = new ProductDAOImpl();
dirDAO = new ProductDirDAOImpl();
}

protected void service(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
req.setCharacterEncoding("UTF-8");
resp.setCharacterEncoding("UTF-8");
//做请求判断是crud的哪一个 进行请求分发操作
String cmd = req.getParameter("cmd");
if ("save".equals(cmd)) {
saveOrUpdate(req, resp);
} else if ("delete".equals(cmd)) {
delete(req, resp);
} else if ("edit".equals(cmd)) {
edit(req, resp);
} else {
query(req, resp);
}
}

protected void query(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
ProductQueryObject qo = new ProductQueryObject();
request2Object(req, qo);
//接受请求封装成对象
req.setAttribute("qo", qo);//做数据回显
req.setAttribute("dirs", dirDAO.dirs().toArray());
PageResult pageResult = dao.pageQuery(qo, "product");
req.setAttribute("pageResult", pageResult);
req.getRequestDispatcher("/WEB-INF/views/page.jsp").forward(req, resp);
}

protected void delete(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
String id = req.getParameter("id");
dao.delete(Long.valueOf(id));
resp.sendRedirect("/query?cmd=query");

}

protected void saveOrUpdate(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
Product p = new Product();
this.request2CrudObject(req, p);
if (p.getId() != null) {
dao.update(p);
} else {
dao.save(p);
}
resp.sendRedirect("/query");

}

protected void edit(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
String id = req.getParameter("id");
if (StringUtil.hasLength(id)) {
Product oldProduct = dao.get(Long.valueOf(id));
req.setAttribute("oldProduct", oldProduct);
}
req.setAttribute("edit_dirs", dirDAO.dirs());
req.getRequestDispatcher("/WEB-INF/views/edit.jsp").forward(req, resp);
}

private void request2Object(HttpServletRequest req, ProductQueryObject qo) {
String keyword = req.getParameter("keyword");
String name = req.getParameter("name");
String dirId = req.getParameter("dirId");
String minPrice = req.getParameter("minPrice");
String maxPrice = req.getParameter("maxPrice");
String currentPage = req.getParameter("currentPage");
String pageSize = req.getParameter("pageSize");
if (StringUtil.hasLength(keyword)) {
qo.setKeyword(keyword);
}
if (StringUtil.hasLength(name)) {
qo.setName(name);
}
if (StringUtil.hasLength(dirId) && Integer.valueOf(dirId) != -1) {
qo.setDir_id(Long.valueOf(dirId));
}
if (StringUtil.hasLength(minPrice)) {
qo.setMinPrice(new BigDecimal(minPrice));
}
if (StringUtil.hasLength(maxPrice)) {
qo.setMaxPrice(new BigDecimal(maxPrice));
}
if (StringUtil.hasLength(currentPage)) {
qo.setCurrentPage(Integer.valueOf(currentPage));
}
if (StringUtil.hasLength(pageSize)) {
qo.setPageSize(Integer.valueOf(pageSize));
}
}

private void request2CrudObject(HttpServletRequest req, Product p) {
//做crud请求的对象封装操作
String id = req.getParameter("id");
String productName = req.getParameter("productName");
String salePrice = req.getParameter("salePrice");
String costPrice = req.getParameter("costPrice");
String dir_id = req.getParameter("dir_id");
String brand = req.getParameter("brand");
String cutoff = req.getParameter("cutoff");
String supplier = req.getParameter("supplier");
if (StringUtil.hasLength(dir_id)) {
ProductDir dir = new ProductDir();
dir.setId(Long.valueOf(dir_id));
p.setProductDir(dir);
}
if (StringUtil.hasLength(id)) {
p.setId(Long.valueOf(id));
}
p.setProductName(productName);
p.setSalePrice(new BigDecimal(salePrice));
p.setCostPrice(new BigDecimal(costPrice));
p.setBrand(brand);
p.setCutoff(Double.valueOf(cutoff));
p.setSupplier(supplier);
}

}


然后我们所创建的PageResult结果集对象的处理代码

package com._jerry._result;

import java.util.Arrays;
import java.util.List;
import lombok.Getter;

@Getter
@SuppressWarnings("all")
public class PageResult {//商品结果集查询对象
private List listData;
private Integer totalCount;

private Integer currentPage = 1;//设置默认值
private Integer pageSize = 5;
private Integer beginPage = 1;//首页
private Integer prevPage;//上一页
private Integer nextPage;//下一页
private Integer totalPage;//总页数

private List<Integer> pageSizeItems = Arrays.asList(3,5,10);
/**
* @param listData
* @param totalCount
* @param currentPage
* @param pageSize
*/
public PageResult(List listData, Integer totalCount, Integer currentPage,
Integer pageSize) {
this.listData = listData;
this.totalCount = totalCount;
this.currentPage = currentPage;
this.pageSize = pageSize;

this.prevPage = this.currentPage - 1 >= 1 ? this.currentPage - 1: this.beginPage;
this.totalPage = this.totalCount % this.pageSize == 0 ? this.totalCount / this.pageSize :
this.totalCount / this.pageSize + 1;
this.nextPage = this.currentPage + 1 <= this.totalPage ? this.currentPage + 1 :
this.totalPage;
}

}


抽取的公用查询IQuery的工具类

package com._jerry._util;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com._jerry._Interface.IQuery;
import com._jerry._Interface.IResultSetHandler;
import com._jerry._domain.Product;
import com._jerry._jdbcTemplate.JdbcTemplate;
import com._jerry._result.PageResult;

public class QueryUtil {
//通用高级查询工具类
/**
* 分页查询操作
* @param qo SQL拼接语句
* @param tableName 表名
* @param rsh 处理结果集
* @return 分页结果集对象
*/
@SuppressWarnings("all")
public static PageResult doQuery(IQuery qo,String tableName,IResultSetHandler rsh){
//结果集查询
String baseSql = "SELECT * FROM "+tableName+qo.getQuery()+" LIMIT ?,? ";
List<Object> newParams = new ArrayList<>(qo.getParameters());
newParams.add((qo.getCurrentPage() - 1)* qo.getPageSize() );//offset指数据开始索引的位置
newParams.add(qo.getPageSize());
List<Product> listData = JdbcTemplate.query(baseSql, rsh, newParams.toArray());

//结果总数查询
String countSql = "SELECT COUNT(*) FROM "+tableName+qo.getQuery();
Integer totalCount = JdbcTemplate.query(countSql, new IResultSetHandler<Long>() {
public Long handler(ResultSet rs) throws SQLException {
if (rs.next()) {
return rs.getLong(1);
}
return 0L;
}
}, qo.getParameters().toArray()).intValue();

return new PageResult(listData, totalCount, qo.getCurrentPage(), qo.getPageSize());

}
}


package com._jerry._Interface;

import java.util.List;

public interface IQuery {

/**
* 用来获取存放参数的集合
* @return
*/

List<Object> getParameters();

/**
* 高级查询的当前页
* @return
*/

Integer getCurrentPage();

/**
* @return 获取每页多少条数据
*/
Integer getPageSize();
/**
* 获取拼接的sql语句
* @return
*/
String getQuery();

}


封装的QueryObject查询对象共有方法

package com._jerry._implement;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import com._jerry._Interface.IQuery;

public class QueryObject implements IQuery{
//用来存储设置参数
private List<Object> parameters = new ArrayList<>();
//用来存储sql语句的条件语句
private List<String> conditions = new ArrayList<>();
public String getQuery() {
parameters.clear();
conditions.clear();
StringBuilder sql = new StringBuilder(200);
this.customizeQuery();
for (int i = 0; i < conditions.size(); i++) {
if (i == 0) {
sql.append(" WHERE ");
}else {
sql.append(" AND ");
}
sql.append(conditions.get(i));
}
return sql.toString();
}

public List<Object> getParameters() {
return this.parameters;
}

protected void addQuery(String condition,Object...params) {
this.conditions.add("("+condition+")");
this.parameters.addAll(Arrays.asList(params));
}
//暴露一个方法给子类添加自己的查询方法
protected void customizeQuery() {

}

//暴露一个方法给子类判断字符串是否为空
protected boolean hasLength(String str) {
return str != null && !"".equals(str.trim());
}

public Integer getCurrentPage() {
return null;
}

public Integer getPageSize() {
return null;
}

}


当前商品的查询对象和sql语句拼接条件

package com._jerry._implement;

import java.math.BigDecimal;
import lombok.Getter;
import lombok.Setter;

@Getter@Setter
public class ProductQueryObject extends QueryObject{
private String name;
private BigDecimal minPrice;
private BigDecimal maxPrice;
private Long dir_id;
private String  keyword;
//封装分页查询对象中用户传入的二个数据
private Integer currentPage = 1;
private Integer pageSize = 5;//设置默认值

protected void customizeQuery() {
if (hasLength(name)) {
//语句前面的空格不能忘记
addQuery(" productName LIKE ?", "%"+name+"%");
}
if (minPrice != null) {
addQuery(" salePrice >= ?", minPrice);
}
if (maxPrice != null) {
addQuery(" salePrice <=  ?", maxPrice);
}
if (dir_id != null) {
addQuery(" dir_id = ?", dir_id);
}
if (hasLength(keyword)) {
addQuery(" productName LIKE ? OR brand LIKE ?", "%"+keyword+"%","%"+keyword+"%");
}

}

}


结果集处理器

package com._jerry._Interface;

import java.sql.ResultSet;
import java.sql.SQLException;

public interface IResultSetHandler<T> {
T handler(ResultSet rs) throws SQLException;
}


package com._jerry._result;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com._jerry._Interface.IResultSetHandler;
import com._jerry._domain.Product;
import com._jerry._domain.ProductDir;
import com._jerry._implement.ProductDirDAOImpl;

public class ResultSetHandler implements IResultSetHandler<List<Product>> {
//定义一个Map集合来做分类对象的Cache
private Map<Long,ProductDir> cache = new HashMap<>();
private ProductDirDAOImpl dirs = new ProductDirDAOImpl();
public List<Product> handler(ResultSet rs) throws SQLException {
List<Product> list = new ArrayList<>();
while (rs.next()) {
Product product = new Product();
list.add(product);
product.setProductName(rs.getString("productName"));
product.setBrand(rs.getString("brand"));
product.setCostPrice(rs.getBigDecimal("costPrice"));
product.setCutoff(rs.getDouble("cutoff"));
product.setSalePrice(rs.getBigDecimal("salePrice"));
product.setId(rs.getLong("id"));
product.setSupplier(rs.getString("supplier"));
Long dir_id = rs.getLong("dir_id");
if (dir_id != null && dir_id != 0) {
ProductDir dir = cache.get(dir_id);
if (dir == null) {
dir = dirs.getDir(dir_id);
//缓存设计
product.setProductDir(dir);
cache.put(dir_id, dir);
}
product.setProductDir(dir);
}

}
return list;
}

}


以上的代码就不附带JdbcTemplate工具类代码了

综合上述代码的演示,在分页结果集PageResult类中有二个字段值是会设值默认值,而且最终决定他们值的是操作用户,用户需要传入两条数据(用户设置的):

currentPage = 1;

pageSize = 10;//原因在于所有的查询对象都可以拥有分页操作

所以我们在servlet中也要接收这二条参数,将其封装在查询对象中一起传入查询对象中.最终我们需要在后端来实现计算的有三个字段值

总页数/末页(totalPage):

totalPage = totalCount % pageSize == 0 ? totalCount / pageSize : totalCount / pageSize + 1;

上一页(prevPage):

prevPage = currentPage - 1 >= 1 ? currentPage - 1 : 1;

下一页(nextPage):

nextPage = currentPage + 1 <= totalPage ? currentPage + 1 : totalPage;

以上还有一个问题:

在翻页的时候,丢失了高级查询的数据:

为什么会丢失:

1):之前我们把高级查询的数据,共享在请求中.

2):但是,翻页的(上一页/下一页)都是超链接,每次点击都会重新发送一个新的请求.

既然是新的请求,所以不能享有上一个请求中的数据.

分析问题:

高级查询表单中封装了所有的查询信息.

翻页的超链接,携带有当前页信息.

解决方案:

把翻页的信息存储到高级查询表单中.

使用JavaScript来做提交高级查询表单.

<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>商品列表</title>
<script type="text/javascript">
//使用JavaScript方法来解决高级查询的数据丢失问题
function goPage(pageNum){
//把翻页的代码存入高级查询表单中
document.getElementById("currentPage").value = pageNum;
document.getElementById("pageSize").value = document.getElementById("ps").value;
//提交表单 因为表单一个只有一个所以获取第0个
document.forms[0].submit();
}
</script>
</head>
<body>
<h3 align="center">货品信息表</h3>
<form action="/query" method="post">
<input type="hidden" name="currentPage" id="currentPage" value="1"/>
<input type="hidden" name="pageSize" id="pageSize" value="3"/>
<div align="center">
商品名称:<input type="search" name="name" value="${qo.name}" /> 价格区间:<input
type="number" name="minPrice" value="${qo.minPrice}" />- <input
type="number" name="maxPrice" value="${qo.maxPrice}" /> <select
name="dirId">
<option value="-1">请选择分类</option>
<c:forEach items="${dirs}" var="dir">
<c:if test="${dir.id != 1}">
<option value="${dir.id}" ${dir.id == qo.dir_id?"selected":""}>${dir.dirName}</option>
</c:if>
</c:forEach>
</select> <input type="text" name="keyword" value="${qo.keyword}" placeholder="商品名称/商品品牌"
style="width: 150px" /> <input type="submit" value="查询"
style="background-color: orange;">
<a href="/query?cmd=edit">添加商品信息</a>
</div>
</form>
<table border="1" width="100%" cellpadding="0" cellspacing="0">
<tr style="background-color: orange;" align="center">
<th>货品编号</th>
<th>货品名称</th>
<th>货品品牌</th>
<th>货品分类</th>
<th>供 应 商</th>
<th>零 售 价</th>
<th>成 本 价</th>
<th>折  扣</th>
<th>操  作</th>
</tr>
<c:forEach items="${pageResult.listData}" var="p" varStatus="times">
<tr style='background-color:${times.count % 2 == 0 ? "gray" : ""};'>
<td>${p.id}</td>
<td>${p.productName}</td>
<td>${p.brand}</td>
<td>${p.productDir.dirName}</td>
<td>${p.supplier}</td>
<td>${p.salePrice}</td>
<td>${p.costPrice}</td>
<td>${p.cutoff}</td>
<td>
<a href="/query?cmd=edit&id=${p.id}">编辑</a>
<a href="/query?cmd=delete&id=${p.id}">删除</a>
</td>
</tr>
</c:forEach>
<tr>
<td colspan="9" align="right">
<a href="javascript:goPage(${pageResult.beginPage})">首页</a>
<a href="javascript:goPage(${pageResult.prevPage})">上一页</a>
<a href="javascript:goPage(${pageResult.nextPage})">下一页</a>
<a href="javascript:goPage(${pageResult.totalPage})">末页</a>
总页数:${pageResult.totalPage},当前第${pageResult.currentPage}/${pageResult.totalPage}页 ,
一共${pageResult.totalCount}条数据,
每页显示
<select id="ps" onchange="goPage(1)">
<c:forEach items="${pageResult.pageSizeItems}" var="ps">
<option ${pageResult.pageSize == ps ? "selected":""}>${ps}</option>
</c:forEach>
</select>条数据
</td>
</tr>
</table>
</body>
</html>


<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>商品编辑页面</title>
</head>
<body>
<form action="/query?cmd=save" method="post">
<input type="hidden" name="id" value="${oldProduct.id}"/>
<table border="1" cellpadding="0" cellspacing="0">
<tr>
<td>货品名称</td>
<td><input type="text" name="productName" value='${oldProduct.productName}' required/></td>
</tr>
<tr>
<td>货品品牌</td>
<td><input type="text" name="brand" value='${oldProduct.brand}' required/></td>
</tr>
<tr>
<td>供 应 商</td>
<td><input type="text" name="supplier"  value='${oldProduct.supplier}' required/></td>
</tr>
<tr>
<td>零 售 价</td>
<td><input type="number" name="salePrice" value='${oldProduct.salePrice}' required min="0"/></td>
</tr>
<tr>
<td>成 本 价</td>
<td><input type="number" name="costPrice" value='${oldProduct.costPrice}' required min="0"/></td>
</tr>
<tr>
<td>折  扣</td>
<td><input type="text" name="cutoff" value='${oldProduct.cutoff}' required/></td>
</tr>
<tr>
<td>商品分类</td>
<td>
<select name="dir_id">
<c:forEach items="${edit_dirs}" var="dir">
<c:if test="${dir.id != 1}">
<option value="${dir.id}" ${dir.id == oldProduct.productDir.id?"selected":""} >
${dir.dirName}</option>
</c:if>
</c:forEach>
</select>
</td>
</tr>
<tr>
<td colspan="2"><input type="submit" value="提交"/></td>
</tr>
</table>

</form>
</body>
</html>


以上就是使用JavaScript代码来解决高级分页查询中数据丢失的问题.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息