环境:oracle11g、myeclipse2014

首先在web项目中添加spring框架

现在已经添加完spring框架了

然后我们开始添加Hibernate框架

到这一步Hibernate框架就添加完成了

applicationContext.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" xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd"> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="url" value="jdbc:oracle:thin:@127.0.0.1:1521:orcl">
</property>
<property name="username" value="system"></property>
<property name="password" value=""></property>
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"></property>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.Oracle9Dialect
</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">true</prop>
</props>
</property>
<!-- <property name="annotatedClasses"> <list> <value>com.bdqn.pojo.Dept</value>
<value>com.bdqn.pojo.Emp</value> </list> </property> -->
<property name="packagesToScan" value="com.bdqn.pojo"></property>
</bean> <context:component-scan base-package="com.bdqn" /> <bean id="txManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean> <tx:annotation-driven transaction-manager="txManager" /> </beans>

然后开始配置struts2框架

到现在struts2框架也整合进来了

然后使用Hibernate的反向工程创建实体类

点击finish,然后实体类就创建好了,接下来就可以开始写代码了

dao层接口

package com.bdqn.dao;

import java.util.List;

import com.bdqn.pojo.Emp;

public interface EmpDao {

    public List<Emp> findAll();
}

dao层实现

package com.bdqn.dao.impl;

import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.stereotype.Repository; import com.bdqn.dao.EmpDao;
import com.bdqn.pojo.Emp; @Repository("empDao")
public class EmpDaoImpl extends HibernateDaoSupport implements EmpDao { @Autowired
public EmpDaoImpl(@Qualifier("sessionFactory") SessionFactory sessionFactory) {
this.setSessionFactory(sessionFactory);
}
public EmpDaoImpl() {
} @Override
public List<Emp> findAll() {
// TODO Auto-generated method stub
return this.getHibernateTemplate().find("from Emp");
} }

service层接口

package com.bdqn.service;

import java.util.List;

import com.bdqn.pojo.Emp;

public interface EmpService {

    public List<Emp> findAll();
}

service层实现

package com.bdqn.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import com.bdqn.dao.EmpDao;
import com.bdqn.pojo.Emp;
import com.bdqn.service.EmpService; @Service("empService")
@Transactional
public class EmpServiceImpl implements EmpService { @Autowired
private EmpDao empDao; public EmpDao getEmpDao() {
return empDao;
} public void setEmpDao(EmpDao empDao) {
this.empDao = empDao;
} @Override
@Transactional(readOnly = true)
public List<Emp> findAll() {
// TODO Auto-generated method stub
return empDao.findAll();
} }

Action(web):

package com.bdqn.web;

import java.util.List;
import java.util.Map; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller; import com.bdqn.pojo.Emp;
import com.bdqn.service.EmpService;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport; @Controller
public class EmpAction extends ActionSupport { @Autowired
private EmpService empService; public EmpService getEmpService() {
return empService;
} public void setEmpService(EmpService empService) {
this.empService = empService;
} public String execute(){
Map<String, Object> request = (Map<String, Object>) ActionContext.getContext().get("request");
List<Emp> emps = empService.findAll();
request.put("emps", emps);
return SUCCESS;
}
}

struts.xml配置文件

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<package name="def" namespace="/" extends="struts-default">
<action name="empAction" class="com.bdqn.web.EmpAction">
<result>/index.jsp</result>
</action>
</package>
</struts>

jsp页面:

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>"> <title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head> <body>
<c:forEach items="${emps}" var="emp">
${emp.ename }<br/>
</c:forEach>
</body>
</html>

到这一步恭喜,你的ssh项目搭建完了

然后部署项目发布

在浏览器上输入http://localhost:8080/你的项目命/empAction.action就可以访问项目了

快速搭建ssh项目的更多相关文章

  1. MyEclipse8.5快速搭建SSH框架

    来源于:http://jingyan.baidu.com/article/a378c960a78125b3282830cc.html MyEclipse8.5快速搭建SSH框架 使用版本: Strut ...

  2. Myeclipse插件快速生成ssh项目并配置注解 在action层注入service的超详细过程

    最近发现,我对于ssh的 自动注入配置 还是不熟悉,于是整理了一下 终于做了一个 简单的 注入配置出来. 以前都是在applicationContext.xml 里面这样配 <bean id=& ...

  3. Spring Boot入门-快速搭建web项目

    Spring Boot 概述: Spring Boot makes it easy to create stand-alone, production-grade Spring based Appli ...

  4. 快速搭建Vue项目

    快速搭建Vue项目 第一次安装vue项目Vue推荐开发环境Node.js 6.2.0.npm 3.8.9.webpack 1.13.vue-cli 2.5.1.webstrom2016 安装环境: 安 ...

  5. 在线官网Spring Initializr 或 IntelliJ IDEA 快速搭建springboot项目

    Spring Boot是由Pivotal团队提供的全新框架,设计目的是用来简化新Spring应用的初始搭建以及开发过程.它主要推崇的是'消灭配置’,实现零配置. 那么,如何快速新建一个一个spring ...

  6. (05节)快速搭建SSM项目

    1.1  快速搭建Web项目 注意点:name:archetypeCatalog,value:internal 原因:Intellij IDEA根据maven archetype的本质,执行mvn a ...

  7. 小D课堂-SpringBoot 2.x微信支付在线教育网站项目实战_2-2.快速搭建SpringBoot项目,采用IDEA

    笔记 2.快速搭建SpringBoot项目,采用IDEA     简介:使用SpringBoot start在线生成项目基本框架并导入到IDEA中 参考资料:         IDEA使用文档    ...

  8. 小D课堂-SpringBoot 2.x微信支付在线教育网站项目实战_2-1.快速搭建SpringBoot项目,采用Eclipse

    笔记 1.快速搭建SpringBoot项目,采用Eclipse     简介:使用SpringBoot start在线生成项目基本框架并导入到eclipse中 1.站点地址:http://start. ...

  9. 使用IDEA快速搭建Springboot项目

    Spring Boot是由Pivotal团队提供的全新框架,设计目的是用来简化新Spring应用的初始搭建以及开发过程.它主要推崇的是'消灭配置’,实现零配置. 下面就介绍一下如何使用idea快速搭建 ...

随机推荐

  1. Samba文件共享服务设置

    SMB的主程序 smbd:SMB-TCP139,CIFS-TCP445 nmbd:NetBios-UDP137,138 SMB主程序对应的两个服务 /etc/init.d/smb /etc/init. ...

  2. python面向对象继承

    class A(object):pass # 括号中可称为父类,基类,超类 class B:pass # 父类,基类,超类 class A_son(A,B):pass # 子类,派生类 class A ...

  3. 实现一个自己的IOC

    实现一个自己的IOC package com.IocExample; import java.lang.reflect.Constructor; import java.lang.reflect.In ...

  4. git只提交修改部分的代码

    思路: 先用git status 查找出哪些文件被修改过了,然后 只git commit odin/code/pom.xml 1. $ git status (查看当前更改的代码) On branch ...

  5. Linux_CentOS常用命令和shell命令技巧

    Linux_CentOS常用命令 关机 init 重启 init 列出当前目录的下的文件 ls //列出当前目录下的文件 ll //列出当前目录下的文件信息 等同ls -l 命令 切换目录 cd 目录 ...

  6. Python适配器模式代码

    Python设计模式之适配器模式,代码,思考等 # -*- coding: utf-8 -*- # author:baoshan class Computer: def __init__(self, ...

  7. html两端对齐的代码

    html语言两端对齐的代码为: <p style="text-align:justify; text-justify:inter-ideograph;"> 文字,需要对 ...

  8. 软件定义网络基础---OF-Config协议

    交换机与控制器继续通信前,是需要对其功能.特性以及资源进行配置才能进行工作,这些配置是如何实现的?是由专门的配置协议指导完成的 一:OF-Config协议 是OpenFlow交换机管理配置协议,是Op ...

  9. 算法习题---5-8图书管理系统*****<双向迭代器>(UVa230)

    一:题目 就是输入一系列书本名和作者名,然后输入命令模拟借书和还书,再输出归还的书的摆放位置.要求有两点: 需要对归还的书做特殊排序处理:作者名相同,则书本按书名从小到大排序:否则书本按作者名大小排序 ...

  10. FastDFSClient工具类

    import org.csource.common.NameValuePair;import org.csource.fastdfs.ClientGlobal;import org.csource.f ...