struts_crm练习(条件查询、添加)

1、导包

(1)导入hibernate相关的包:

 (2)导入struts2相关的包:

 2、条件查询

(1)条件查询的流程图:

 list.jsp可以向Action传递参数(即查询的条件),这里用的是离线查询DetachedCriteria,使用离线查询不用在dao层封装查询的参数,这里直接在web层封装查询的参数,最终,将得到的对象传递到dao层与session关联。

(2)遍历接受的数据:

方式一:

先引入:

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<c:forEach items="${list}" var="customer">
        <TR
       style="FONT-WEIGHT: normal; FONT-STYLE: normal; BACKGROUND-COLOR: white; TEXT-DECORATION: none">
           <TD>${customer.cust_name }</TD>
           <TD>${customer.cust_level }</TD>
           <TD>${customer.cust_source }</TD>
           <TD>${customer.cust_linkman }</TD>
           <TD>${customer.cust_phone }</TD>
           <TD>${customer.cust_mobile }</TD>
           <TD>
           <a href="${pageContext.request.contextPath }/customerServlet?method=edit&custId=${customer.cust_id}">修改</a>
            &nbsp;&nbsp;
            <a href="${pageContext.request.contextPath }/customerServlet?method=delete&custId=${customer.cust_id}">删除</a>
           </TD>
           </TR>

         </c:forEach>

方式二:

先引入:

<%@ taglib uri="/struts-tags" prefix="s" %>
<s:iterator value="#list" var="cust" >
<TR         
    style="FONT-WEIGHT: normal; FONT-STYLE: normal; BACKGROUND-COLOR: white; TEXT-DECORATION: none">
    <TD>
    <s:property value="#cust.cust_name" />
    </TD>
    <TD>
    <s:property value="#cust.cust_level" />
    </TD>
    <TD>
    <s:property value="#cust.cust_source" />
     </TD>
     <TD>
     <s:property value="#cust.cust_linkman" />
      </TD>
     <TD>
      <s:property value="#cust.cust_phone" />
      </TD>
      <TD>
      <s:property value="#cust.cust_mobile" />
      </TD>
      <TD>
       <a href="${pageContext.request.contextPath }/customerServlet?method=edit&custId=${customer.cust_id}">修改</a>
       &nbsp;&nbsp;
       <a href="${pageContext.request.contextPath }/customerServlet?method=delete&custId=${customer.cust_id}">删除</a>
        </TD>
        </TR>
</s:iterator>

3、添加

 

 在action中封装表单的数据用到的是模型驱动,将数据封装为对象之后作为参数传递给相应地函数。

原文地址:https://www.cnblogs.com/zhai1997/p/12487367.html