热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

Struts2(六)用Struts完成客户列表显示

Struts完成客户列表显示所用的基础知识在之前的随笔中已经讲过。这篇是介绍如何使用Struts完成客户列表显示。下面是完成的代码执行逻辑图:抽取项目部分代码相信大家

Struts完成客户列表显示 所用的基础知识 在之前的随笔中已经讲过。这篇是介绍如何使用Struts 完成客户列表显示  。

下面是  完成的代码执行逻辑图:

 

抽取项目部分代码 相信大家认真看一遍就明白的:

jsp 页面代码片段:

<TABLE cellSpacing&#61;0 cellPadding&#61;3 width&#61;165 align&#61;center border&#61;0><TBODY><TR><TD class&#61;mainMenu onClick&#61;"MenuDisplay(&#39;table_1&#39;);"><SPANclass&#61;span id&#61;table_1Span>&#xff0b;SPAN> 客户管理TD>TR><TR><TD><TABLE id&#61;table_1 style&#61;"DISPLAY: none" cellSpacing&#61;0cellPadding&#61;2 width&#61;155 align&#61;center border&#61;0><TBODY><TR><TD class&#61;menuSmall><A class&#61;style2 href&#61;"${pageContext.request.contextPath}/jsp/customer/add.jsp" target&#61;main>&#xff0d; 新增客户A>TD>TR><TR> <TD class&#61;menuSmall><A class&#61;style2 href&#61;"${pageContext.request.contextPath}/CustomerAction_list"target&#61;main>&#xff0d; 客户列表A>TD>TR>TBODY>TABLE>TD>TR><TR><TD background&#61;images/new_027.jpg height&#61;1>TD>TR><TR><TD class&#61;mainMenu onClick&#61;"MenuDisplay(&#39;table_2&#39;);"><SPANclass&#61;span id&#61;table_2Span>&#xff0b;SPAN> 联系人管理TD>TR><TR><TD><TABLE id&#61;table_2 style&#61;"DISPLAY: none" cellSpacing&#61;0cellPadding&#61;2 width&#61;155 align&#61;center border&#61;0><TBODY><TR><TD class&#61;menuSmall><A class&#61;style2 href&#61;"${pageContext.request.contextPath}/jsp/linkman/add.jsp"target&#61;main>&#xff0d; 新增联系人A>TD>TR><TR><TD class&#61;menuSmall><A class&#61;style2 href&#61;"linkmanServlet?method&#61;list"target&#61;main>&#xff0d;联系人列表A>TD>TR>TBODY>TABLE>TD>TR><TR><TD background&#61;images/new_027.jpg height&#61;1>TD>TR><TR><TD class&#61;mainMenu onClick&#61;"MenuDisplay(&#39;table_5&#39;);"><SPANclass&#61;span id&#61;table_5Span>&#xff0b;SPAN> 客户拜访管理TD>TR><TR><TD><TABLE id&#61;table_5 style&#61;"DISPLAY: none" cellSpacing&#61;0cellPadding&#61;2 width&#61;155 align&#61;center border&#61;0><TBODY><TR><TD class&#61;menuSmall><A class&#61;style2 href&#61;"#"target&#61;main>&#xff0d;新增客户拜访A>TD>TR><TR><TD class&#61;menuSmall><A class&#61;style2 href&#61;"#"target&#61;main>&#xff0d;客户拜访列表A>TD>TR>TBODY>TABLE>TD>TR><TR><TD background&#61;images/new_027.jpg height&#61;1>TD>TR><TR><TD class&#61;mainMenu onClick&#61;"MenuDisplay(&#39;table_3&#39;);"><SPANclass&#61;span id&#61;table_3Span>&#xff0b;SPAN> 综合查询TD>TR><TR><TD><TABLE id&#61;table_3 style&#61;"DISPLAY: none" cellSpacing&#61;0cellPadding&#61;2 width&#61;155 align&#61;center border&#61;0><TBODY><TR><TD class&#61;menuSmall><A class&#61;style2 href&#61;"#"target&#61;main>&#xff0d; 客户信息查询A>TD>TR><TR><TD class&#61;menuSmall><A class&#61;style2 href&#61;"#"target&#61;main>&#xff0d; 联系人信息查询A>TD>TR><TR><TD class&#61;menuSmall><A class&#61;style2 href&#61;"#"target&#61;main>&#xff0d; 客户拜访记录查询A>TD>TR>TBODY>TABLE>TD>TR><TR><TD background&#61;images/new_027.jpg height&#61;1>TD>TR><TR><TD class&#61;mainMenu onClick&#61;"MenuDisplay(&#39;table_4&#39;);"><SPANclass&#61;span id&#61;table_4Span>&#xff0b;SPAN> 统计分析TD>TR><TR><TD><TABLE id&#61;table_4 style&#61;"DISPLAY: none" cellSpacing&#61;0cellPadding&#61;2 width&#61;155 align&#61;center border&#61;0><TBODY><TR><TD class&#61;menuSmall><A class&#61;style2 href&#61;"#"target&#61;main>&#xff0d;客户行业统计A>TD>TR><TR><TD class&#61;menuSmall><A class&#61;style2 href&#61;"#"target&#61;main>&#xff0d;客户来源统计A>TD>TR>TBODY>TABLE>TD>TR><TR><TD background&#61;images/new_027.jpg height&#61;1>TD>TR><TR><TD class&#61;mainMenu onClick&#61;"MenuDisplay(&#39;table_6&#39;);"><SPANclass&#61;span id&#61;table_6Span>&#xff0b;SPAN>系统管理TD>TR><TR><TD><TABLE id&#61;table_6 style&#61;"DISPLAY: none" cellSpacing&#61;0cellPadding&#61;2 width&#61;155 align&#61;center border&#61;0><TBODY><TR><TD class&#61;menuSmall><A class&#61;style2 href&#61;"#"target&#61;main>&#xff0d;角色管理A>TD>TR><TR><TD class&#61;menuSmall><A class&#61;style2 href&#61;"#"target&#61;main>&#xff0d;用户管理A>TD>TR><TR><TD class&#61;menuSmall><A class&#61;style2 href&#61;"#"target&#61;main>&#xff0d;数据字典A>TD>TR>TBODY>TABLE>TD>TR>TBODY>TABLE>

 

Action类 代码&#xff1a;

1 public class CustomerAction extends ActionSupport {
2 private CustomerService cs &#61; new CustomerServiceImpl();
3
4 public String list() throws Exception {
5 //1 接受参数
6 String cust_name &#61; ServletActionContext.getRequest().getParameter("cust_name");
7 //2 创建离线查询对象
8 DetachedCriteria dc &#61;DetachedCriteria.forClass(Customer.class);
9 //3 判断参数拼装条件
10 //StringUtils.isNotBlank 静态方法 判断
11 //当cust_name 不为null 不为 ""&#xff08;空字符串&#xff09; ,不为空格时 返回true
12 if(StringUtils.isNotBlank(cust_name)){
13 dc.add(Restrictions.like("cust_name", "%"&#43;cust_name&#43;"%"));
14 }
15 //4 调用Service将离线对象传递
16 List list &#61; cs.getAll(dc);
17 //5 将返回的list放入request域.转发到list.jsp显示
18 //引用ServletActionContext类的静态方法getRequest
19 //getRequest返回HttpServletRequest对象
20 ServletActionContext.getRequest().setAttribute("list", list);
21
22 return "list";
23 }
24 }

Struts.xml &#xff1a;

1 xml version&#61;"1.0" encoding&#61;"UTF-8"?>
2 DOCTYPE struts PUBLIC
3 "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
4 "http://struts.apache.org/dtds/struts-2.3.dtd">
5 <struts>
6
10 <constant name&#61;"struts.devMode" value&#61;"true">constant>
11 <package name&#61;"crm" namespace&#61;"/" extends&#61;"struts-default" >
12 <action name&#61;"CustomerAction_*" class&#61;"cn.itheima.web.action.CustomerAction" method&#61;"{1}" >
13 <result name&#61;"list" >/jsp/customer/list.jspresult>
14 action>
15 package>
16 struts>

ServiceImpl 类

2
3 import java.util.List;
4
5 import org.hibernate.Session;
6 import org.hibernate.Transaction;
7 import org.hibernate.criterion.DetachedCriteria;
8
9 import cn.itheima.dao.CustomerDao;
10 import cn.itheima.dao.impl.CustomerDaoImpl;
11 import cn.itheima.domain.Customer;
12 import cn.itheima.service.CustomerService;
13 import cn.itheima.utils.HibernateUtils;
14
15 public class CustomerServiceImpl implements CustomerService {
16
17 private CustomerDao customerDao &#61; new CustomerDaoImpl();
18
19 public List getAll() {
20 Session session &#61; HibernateUtils.getCurrentSession();
21 //打开事务
22 Transaction tx &#61; session.beginTransaction();
23
24 List list &#61; customerDao.getAll();
25
26
27 //关闭事务
28 tx.commit();
29 return list;
30 }
31
32 public List getAll(DetachedCriteria dc) {
33 Session session &#61; HibernateUtils.getCurrentSession();
34 //打开事务
35 Transaction tx &#61; session.beginTransaction();
36
37 List list &#61; customerDao.getAll(dc);
38
39
40 //关闭事务
41 tx.commit();
42 return list;
43 }
44
45 }

dao层实现类&#xff1a;

2
3 import java.util.List;
4
5 import org.hibernate.Criteria;
6 import org.hibernate.Session;
7 import org.hibernate.Transaction;
8 import org.hibernate.criterion.DetachedCriteria;
9
10 import cn.itheima.dao.CustomerDao;
11 import cn.itheima.domain.Customer;
12 import cn.itheima.utils.HibernateUtils;
13
14 public class CustomerDaoImpl implements CustomerDao {
15 public List getAll() {
16 //1 获得session
17 Session session &#61; HibernateUtils.getCurrentSession();
18 //2 创建Criteria对象
19 Criteria c &#61; session.createCriteria(Customer.class);
20 return c.list();
21 }
22 }

 

转:https://www.cnblogs.com/shaoxiaohuan/p/8526385.html



推荐阅读
  • 本文将介绍如何编写一些有趣的VBScript脚本,这些脚本可以在朋友之间进行无害的恶作剧。通过简单的代码示例,帮助您了解VBScript的基本语法和功能。 ... [详细]
  • 导航栏样式练习:项目实例解析
    本文详细介绍了如何创建一个具有动态效果的导航栏,包括HTML、CSS和JavaScript代码的实现,并附有详细的说明和效果图。 ... [详细]
  • 使用 Azure Service Principal 和 Microsoft Graph API 获取 AAD 用户列表
    本文介绍了一段通用代码示例,该代码不仅能够操作 Azure Active Directory (AAD),还可以通过 Azure Service Principal 的授权访问和管理 Azure 订阅资源。Azure 的架构可以分为两个层级:AAD 和 Subscription。 ... [详细]
  • 优化ListView性能
    本文深入探讨了如何通过多种技术手段优化ListView的性能,包括视图复用、ViewHolder模式、分批加载数据、图片优化及内存管理等。这些方法能够显著提升应用的响应速度和用户体验。 ... [详细]
  • Explore how Matterverse is redefining the metaverse experience, creating immersive and meaningful virtual environments that foster genuine connections and economic opportunities. ... [详细]
  • 本文介绍了如何利用JavaScript或jQuery来判断网页中的文本框是否处于焦点状态,以及如何检测鼠标是否悬停在指定的HTML元素上。 ... [详细]
  • This guide provides a comprehensive step-by-step approach to successfully installing the MongoDB PHP driver on XAMPP for macOS, ensuring a smooth and efficient setup process. ... [详细]
  • 本文详细介绍了如何在Linux系统上安装和配置Smokeping,以实现对网络链路质量的实时监控。通过详细的步骤和必要的依赖包安装,确保用户能够顺利完成部署并优化其网络性能监控。 ... [详细]
  • 深入理解Tornado模板系统
    本文详细介绍了Tornado框架中模板系统的使用方法。Tornado自带的轻量级、高效且灵活的模板语言位于tornado.template模块,支持嵌入Python代码片段,帮助开发者快速构建动态网页。 ... [详细]
  • 深入理解Cookie与Session会话管理
    本文详细介绍了如何通过HTTP响应和请求处理浏览器的Cookie信息,以及如何创建、设置和管理Cookie。同时探讨了会话跟踪技术中的Session机制,解释其原理及应用场景。 ... [详细]
  • DNN Community 和 Professional 版本的主要差异
    本文详细解析了 DotNetNuke (DNN) 的两种主要版本:Community 和 Professional。通过对比两者的功能和附加组件,帮助用户选择最适合其需求的版本。 ... [详细]
  • XNA 3.0 游戏编程:从 XML 文件加载数据
    本文介绍如何在 XNA 3.0 游戏项目中从 XML 文件加载数据。我们将探讨如何将 XML 数据序列化为二进制文件,并通过内容管道加载到游戏中。此外,还会涉及自定义类型读取器和写入器的实现。 ... [详细]
  • Android LED 数字字体的应用与实现
    本文介绍了一种适用于 Android 应用的 LED 数字字体(digital font),并详细描述了其在 UI 设计中的应用场景及其实现方法。这种字体常用于视频、广告倒计时等场景,能够增强视觉效果。 ... [详细]
  • 如何高效创建和使用字体图标
    在Web和移动开发中,为什么选择字体图标?主要原因是其卓越的性能,可以显著减少HTTP请求并优化页面加载速度。本文详细介绍了从设计到应用的字体图标制作流程,并提供了专业建议。 ... [详细]
  • RecyclerView初步学习(一)
    RecyclerView初步学习(一)ReCyclerView提供了一种插件式的编程模式,除了提供ViewHolder缓存模式,还可以自定义动画,分割符,布局样式,相比于传统的ListVi ... [详细]
author-avatar
逍遥微博2011_213
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有