一、条件查询
Jsp页面关键代码:
<form id="Form1" name="Form1" action="${pageContext.request.contextPath}/adminSearchProductList" method="post">
商品名称:<input type="text" name="pname" value="${condition.pname }">
是否热门:<select id="isHot" name="isHot">
<option value="">不限</option>
<option value="0">否</option>
<option value="1">是</option>
</select>
商品类别:<select id="cid" name="cid">
<option value="">不限</option>
<c:forEach items="${categoryList }" var="category">
<option value="${category.cid }">${category.cname }</option>
</c:forEach>
</select>
<input type="submit" value="搜索">
<br/>
Web层:
@WebServlet(name = "adminSearchProductList",
urlPatterns = {
"/adminSearchProductList"})
public class adminSearchProductList extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request,response);
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
//1、收集表单数据
Map<String, String[]> properties = request.getParameterMap();
//2、将散装的查询数据封装到一个VO实体中
Condition condition = new Condition();
try {
BeanUtils.populate(condition, properties);
} catch (IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
}
//3、将实体传递给service层
AdminProductService service = new AdminProductService();
List<Product> productList = null;
try {
productList = service.findProductListByCondition(condition);
} catch (SQLException e) {
e.printStackTrace();
}
//准备商品类别
//获得所有的商品的类别数据
List<Category&g