4. 完成功能.

(1)com.atguigu.ssh.actions包下新建EmployeeAction.java 

  

 package com.atguigu.ssh.actions;

 import java.util.Map;

 import org.apache.struts2.interceptor.RequestAware;

 import com.atguigu.ssh.service.EmployeeService;
import com.opensymphony.xwork2.ActionSupport; public class EmployeeAction extends ActionSupport implements RequestAware{
/**
*
*/
private static final long serialVersionUID = 1L; private EmployeeService employeeService; public void setEmployeeService(EmployeeService employeeService){
this.employeeService=employeeService;
} public String list(){
request.put("employees", employeeService.getAll());
return "list";
} //放到页面里
private Map<String,Object> request;
@Override
public void setRequest(Map<String, Object> arg0) {
this.request=arg0;
} }

  com.atguigu.ssh.dao包下新建EmployeeDao.java

  

 package com.atguigu.ssh.dao;

 import java.util.List;

 import org.hibernate.Session;
import org.hibernate.SessionFactory; import com.atguigu.ssh.entities.Employee; public class EmployeeDao { private SessionFactory sessionFactory; public void setSessionFactory(SessionFactory sessionFactory){
this.sessionFactory=sessionFactory;
} public Session getSession(){
return this.sessionFactory.getCurrentSession();
} public List<Employee> getAll(){
String hql="FROM Employee e LEFT OUTER JOIN FETCH e.department";
return getSession().createQuery(hql).list();
}
}

  com.atguigu.ssh.service包下新建EmployeeService.java 

  

 package com.atguigu.ssh.service;

 import java.util.List;

 import com.atguigu.ssh.dao.EmployeeDao;
import com.atguigu.ssh.entities.Employee; public class EmployeeService { private EmployeeDao employeeDao;
public void setEmployeeDao(EmployeeDao employeeDao){
this.employeeDao=employeeDao;
} public List<Employee> getAll(){
List<Employee> employees = employeeDao.getAll();
return employees;
}
}

(2)完善applicationContext-beans.xml

 <?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> <bean id="employeeDao" class="com.atguigu.ssh.dao.EmployeeDao">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean> <bean id="employeeService" class="com.atguigu.ssh.service.EmployeeService">
<property name="employeeDao" ref="employeeDao"></property>
</bean> <bean id="employeeAction" class="com.atguigu.ssh.actions.EmployeeAction"
scope="prototype">
<property name="employeeService" ref="employeeService"></property>
</bean>
</beans>

(3)完善struts.xml

 <?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd"> <struts> <constant name="struts.enable.DynamicMethodInvocation" value="false" />
<constant name="struts.devMode" value="true" /> <package name="default" namespace="/" extends="struts-default">
<action name="emp-*" class="employeeAction"
method="{1}">
<result name="list">/WEB-INF/views/emp-list.jsp</result>
</action>
</package> </struts>

(4)WebContent下新建index.jsp

 <%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<a href="emp-list">显示所有员工信息List All Employees</a>
</body>
</html>

(5)WebContent-views-emp-list.jsp

 <%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<h3>Employee List Page</h3> <s:if test="#request.employees == null ||#request.size()==0">
没有员工信息
</s:if>
<s:else>
<table border="1" cellpadding="10" cellspacing="0">
<tr>
<td>ID</td>
<td>LASTNAME</td>
<td>EMAIL</td>
<td>BIRTH</td>
<td>CREATETIME</td>
<td>DEPT</td>
</tr>
<s:iterator value="#request.employees">
<tr>
<td>${id}</td>
<td>${lastName}</td>
<td>${email }</td>
<td>${birth}</td>
<td>${createTime}</td>
<td>${department.departmentName}</td>
</tr>
</s:iterator>
</table>
</s:else>
</body>
</html>

(6)修改下web.xml中的信息,注册Struts2

 <?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_2_5.xsd" id="WebApp_ID" version="2.5"> <!-- 配置spring配置文件.xml的名称和位置路径 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext*.xml</param-value>
</context-param> <!-- Bootstraps the root web application context before servlet initialization -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener> <!-- 配置Struts的Filter -->
<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> </web-app>

SSH_框架整合2;

SSH_框架整合2—查询显示的更多相关文章

  1. SSH_框架整合4--添加员工信息

    SSH_框架整合4--添加员工信息 一. 1 index.jsp:添加:<a href="emp-input">添加员工向信息:Add Employees' Infor ...

  2. SSH_框架整合6--修改Edit员工信息

    SSH_框架整合6--修改Edit员工信息 1 加上修改Edit键 (1)emp-list.jsp <td> <a href="emp-input?id=${id }&qu ...

  3. SSH_框架整合5--验证用户名是否可用

    SSH_框架整合5--验证用户名是否可用 1 emp-input.jsp中编写ajax验证用户名是否可用: <script type="text/javascript" SR ...

  4. SSH_框架整合1

    1 WEB环境下配置Spring   因为是在WEB环境中应用Spring,所以要先配置web.xml: (1)WebContent-WEB-INF-lib包中,加入Spring包下的required ...

  5. SSH_框架整合7--整个项目CODE

    一 架构 1Action类 2 配置文件 3 View页面 二  Code 1 src (1)com.atguigu.ssh.actions >EmployeeAction.java packa ...

  6. SSH_框架整合3-删除

    一.普通删除 1 完善src中 类: (1)EmployeeDao.java中: //2 删除 public void delete(Integer id){ String hql="DEL ...

  7. Mybatis框架-联表查询显示问题解决

    需求:查询结果要求显示用户名,用户密码,用户的角色 因为在用户表中只有用户角色码值,没有对应的名称,角色名称是在码表smbms_role表中,这时我们就需要联表查询了. 这里需要在User实体类中添加 ...

  8. 商城02——dubbo框架整合_商品列表查询实现_分页

    1.   课程计划 1.服务中间件dubbo 2.SSM框架整合. 3.测试使用dubbo 4.后台系统商品列表查询功能实现. 5.监控中心的搭建 2.   功能分析 2.1. 后台系统所用的技术 框 ...

  9. SSH框架整合

    SSH框架整合 一.原理图 action:(struts2) 1.获取表单的数据 2.表单的验证,例如非空验证,email验证等 3.调用service,并把数据传递给service Service: ...

随机推荐

  1. PHP字符串——编码与转义

    因为PHP程序经常与HTML页.Web地址(URL)以及数据库交互,所以PHP提供一些函数来帮助你处理这些类型的数据.HTML.Web页地址和数据库命令都是字符串,但是它们每个都要求不同的字符以不同的 ...

  2. 二分查找(Binary Search)

    二分查找(Binary Search): int BinarySearch(int *array, int N, int key) { ; int left, right, mid; left = ; ...

  3. 五 浅谈CPU 并行编程和 GPU 并行编程的区别

    前言 CPU 的并行编程技术,也是高性能计算中的热点,也是今后要努力学习的方向.那么它和 GPU 并行编程有何区别呢? 本文将做出详细的对比,分析各自的特点,为将来深入学习 CPU 并行编程技术打下铺 ...

  4. 230. Kth Smallest Element in a BST

    Given a binary search tree, write a function kthSmallest to find the kth smallest element in it. Not ...

  5. 16年大连网络赛 1006 Football Games

    题目链接:http://acm.hdu.edu.cn/contests/contest_showproblem.php?cid=725&pid=1006 Football Games Time ...

  6. this指针基础介绍

    =================this指针的由来==================== 一个学生可以有多本书一样,而这些书都是属于这个同学的:同理,如果有很多个同学在一起,那么为了确定他们的书不 ...

  7. Mysql 下 Insert、Update、Delete、Order By、Group By注入

    Insert: 语法:INSERT INTO table_name (列1, 列2,...) VALUES (值1, 值2,....) 报错注入: insert into test(id,name,p ...

  8. (转载)Hadoop map reduce 过程获取环境变量

    来源:http://www.linuxidc.com/Linux/2012-07/66337.htm   作者: lmc_wy Hadoop任务执行过程中,在每一个map节点或者reduce节点能获取 ...

  9. python3获取当前目录(转)

    转自:http://www.elias.cn/Python/GetPythonPath?from=Develop.GetPythonPath 1.  以前的方法 如果是要获得程序运行的当前目录所在位置 ...

  10. leetcode 146. LRU Cache ----- java

    esign and implement a data structure for Least Recently Used (LRU) cache. It should support the foll ...