SSH_框架整合2—查询显示

4. 完成功能.

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

  

 1 package com.atguigu.ssh.actions;
 2
 3 import java.util.Map;
 4
 5 import org.apache.struts2.interceptor.RequestAware;
 6
 7 import com.atguigu.ssh.service.EmployeeService;
 8 import com.opensymphony.xwork2.ActionSupport;
 9
10 public class EmployeeAction extends ActionSupport implements RequestAware{
11     /**
12      *
13      */
14     private static final long serialVersionUID = 1L;
15
16     private EmployeeService employeeService;
17
18     public void setEmployeeService(EmployeeService employeeService){
19         this.employeeService=employeeService;
20     }
21
22     public String list(){
23         request.put("employees", employeeService.getAll());
24         return "list";
25     }
26
27     //放到页面里
28     private Map<String,Object> request;
29     @Override
30     public void setRequest(Map<String, Object> arg0) {
31         this.request=arg0;
32     }
33
34 }

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

  

 1 package com.atguigu.ssh.dao;
 2
 3 import java.util.List;
 4
 5 import org.hibernate.Session;
 6 import org.hibernate.SessionFactory;
 7
 8 import com.atguigu.ssh.entities.Employee;
 9
10 public class EmployeeDao {
11
12     private SessionFactory sessionFactory;
13
14     public void setSessionFactory(SessionFactory sessionFactory){
15         this.sessionFactory=sessionFactory;
16     }
17
18     public Session getSession(){
19         return  this.sessionFactory.getCurrentSession();
20     }
21
22     public List<Employee> getAll(){
23         String hql="FROM Employee  e LEFT OUTER JOIN FETCH e.department";
24         return getSession().createQuery(hql).list();
25     }
26 }

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

  

 1 package com.atguigu.ssh.service;
 2
 3 import java.util.List;
 4
 5 import com.atguigu.ssh.dao.EmployeeDao;
 6 import com.atguigu.ssh.entities.Employee;
 7
 8 public class EmployeeService {
 9
10     private EmployeeDao employeeDao;
11     public void setEmployeeDao(EmployeeDao employeeDao){
12         this.employeeDao=employeeDao;
13     }
14
15     public List<Employee> getAll(){
16         List<Employee> employees = employeeDao.getAll();
17         return employees;
18     }
19 }

(2)完善applicationContext-beans.xml

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <beans xmlns="http://www.springframework.org/schema/beans"
 3     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 4     xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
 5
 6     <bean id="employeeDao" class="com.atguigu.ssh.dao.EmployeeDao">
 7         <property name="sessionFactory" ref="sessionFactory"></property>
 8     </bean>
 9
10     <bean id="employeeService" class="com.atguigu.ssh.service.EmployeeService">
11         <property name="employeeDao" ref="employeeDao"></property>
12     </bean>
13
14     <bean id="employeeAction" class="com.atguigu.ssh.actions.EmployeeAction"
15           scope="prototype">
16         <property name="employeeService" ref="employeeService"></property>
17     </bean>
18 </beans>

(3)完善struts.xml

 1 <?xml version="1.0" encoding="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
 6 <struts>
 7
 8     <constant name="struts.enable.DynamicMethodInvocation" value="false" />
 9     <constant name="struts.devMode" value="true" />
10
11     <package name="default" namespace="/" extends="struts-default">
12         <action name="emp-*" class="employeeAction"
13                 method="{1}">
14                 <result name="list">/WEB-INF/views/emp-list.jsp</result>
15         </action>
16     </package>
17
18 </struts>

(4)WebContent下新建index.jsp

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

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

 1 <%@ page language="java" contentType="text/html; charset=UTF-8"
 2     pageEncoding="UTF-8"%>
 3 <%@ taglib prefix="s" uri="/struts-tags" %>
 4 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 5 <html>
 6 <head>
 7 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 8 <title>Insert title here</title>
 9 </head>
10 <body>
11     <h3>Employee List Page</h3>
12
13     <s:if test="#request.employees == null ||#request.size()==0">
14         没有员工信息
15     </s:if>
16     <s:else>
17         <table border="1" cellpadding="10" cellspacing="0">
18             <tr>
19                 <td>ID</td>
20                 <td>LASTNAME</td>
21                 <td>EMAIL</td>
22                 <td>BIRTH</td>
23                 <td>CREATETIME</td>
24                 <td>DEPT</td>
25             </tr>
26             <s:iterator value="#request.employees">
27                 <tr>
28                     <td>${id}</td>
29                     <td>${lastName}</td>
30                     <td>${email }</td>
31                     <td>${birth}</td>
32                     <td>${createTime}</td>
33                     <td>${department.departmentName}</td>
34                 </tr>
35             </s:iterator>
36         </table>
37     </s:else>
38 </body>
39 </html>

(6)修改下web.xml中的信息

1 <context-param>
2         <param-name>contextConfigLocation</param-name>
3         <param-value>classpath:applicationContext*.xml</param-value>
4     </context-param>

SSH_框架整合2;

时间: 2024-08-03 15:14:06

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

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

一 架构 1Action类 2 配置文件 3 View页面 二  Code 1 src (1)com.atguigu.ssh.actions >EmployeeAction.java 1 package com.atguigu.ssh.actions; 2 3 import java.io.ByteArrayInputStream; 4 import java.io.InputStream; 5 import java.io.UnsupportedEncodingException; 6 imp

SSH_框架整合3-删除

一.普通删除 1 完善src中 类: (1)EmployeeDao.java中: 1 //2 删除 2 public void delete(Integer id){ 3 String hql="DELETE FROM Employee e WHERE e.id=?"; 4 getSession().createQuery(hql).setInteger(0,id).executeUpdate(); 5 } (2)EmployeeService.java中: 1 //2删除 2 pub

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

1.   课程计划 1.服务中间件dubbo 2.SSM框架整合. 3.测试使用dubbo 4.后台系统商品列表查询功能实现. 5.监控中心的搭建 2.   功能分析 2.1. 后台系统所用的技术 框架:Spring + SpringMVC + Mybatis+dubbo 前端:EasyUI 数据库:mysql 2.2. 系统间通信 由于淘淘商城是基于SOA的架构,表现层和服务层是不同的工程.所以要实现商品列表查询需要两个系统之间进行通信. 如何实现远程通信? 1.使用WebService:效率

springMVC和Shiro框架整合使用简单示例 【转】

一.目录结构 首先是目录结构如图: 二.pom.xml文件 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0

j2ee框架整合Spring+spring mvc+mybatis

升级报捷:通过服务于服务之间调用,生成二维码,可直接用户手机app(详细查看截图) 框架集成lucene搜索引擎,使您的信息在毫秒内抓取(详细查看截图) 1.  创建.初始化索引.统一搜索入口.搜索结果展现--内容.标题高亮.关键词搜索 2.  高级搜索:高级搜索增加多入口查询(精确查询.模糊查询.前缀查询等),每页显示条数自定义.索引结果数据设置.选择索引文档类型等 3. 通过A系统调用B系统的Rest服务,生成相关的二维码,可以直接用户手机app 源码地址获取 ---------------

模块化服务化原框架整合Springmvc+mybatis+shiro+bootstrap+html5

源码地址获取  1. 使用阿里巴巴Druid连接池(高效.功能强大.可扩展性好的数据库连接池.监控数据库访问性能.支持Common-Logging.Log4j和JdkLog,监控数据库访问) 2. 提供高并发JMS消息处理机制3. 所有功能模块化.所有模块服务化.所有服务原子化的方式,提供可拓展的服务模型,使程序稳定运行,永不宕机4. 提供Wink Rest.Webservice服务,故可作为独立服务平台部署 框架整合: Springmvc + Mybatis + Shiro(权限) + RES

高并发、大数据企业级框架整合maven_Springmvc_Mybatis_Shiro_REST_WebService_JMS_Lucene_Bootstrap

1. 使用阿里巴巴Druid连接池(高效.功能强大.可扩展性好的数据库连接池.监控数据库访问性能.支持Common-Logging.Log4j和JdkLog,监控数据库访问) 2. 提供高并发JMS消息处理机制 3. 所有功能模块化.所有模块服务化.所有服务原子化的方式,提供可拓展的服务模型,使程序稳定运行,永不宕机 4. 提供Wink Rest.Webservice服务,故可作为独立服务平台部署 框架整合: Springmvc + Mybatis + Shiro(权限) + REST(服务)

【javaWeb框架整合】springmvc+mybatis+shiro+restful+Webservice+bootstrap+html5

开发报捷:增加Lucene搜索引擎功能 1. 创建.初始化索引.统一搜索入口.搜索结果展现--内容.标题高亮.关键词搜索 2. 高级搜索:高级搜索增加多入口查询(精确查询.模糊查询.前缀查询等),每页显示条数自定义.索引结果数据设置.选择索引文档类型等) 集成lucene搜索引擎: 1. 使用阿里巴巴Druid连接池(高效.功能强大.可扩展性好的数据库连接池.监控数据库访问性能.支持Common-Logging.Log4j和JdkLog,监控数据库访问) 2. 提供高并发JMS消息处理机制 3.

【企业级框架整合源码】maven+Springmvc+Mybatis+Shiro+REST+WebService+JMS+Lucene+Bootstrap

开发报捷:增加Lucene搜索引擎功能 1. 创建.初始化索引.统一搜索入口.搜索结果展现--内容.标题高亮.关键词搜索 2. 高级搜索:高级搜索增加多入口查询(精确查询.模糊查询.前缀查询等),每页显示条数自定义.索引结果数据设置.选择索引文档类型等) 集成lucene搜索引擎: 1. 使用阿里巴巴Druid连接池(高效.功能强大.可扩展性好的数据库连接池.监控数据库访问性能.支持Common-Logging.Log4j和JdkLog,监控数据库访问) 2. 提供高并发JMS消息处理机制 3.