快速搭建ssh项目
环境: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项目的更多相关文章
- MyEclipse8.5快速搭建SSH框架
来源于:http://jingyan.baidu.com/article/a378c960a78125b3282830cc.html MyEclipse8.5快速搭建SSH框架 使用版本: Strut ...
- Myeclipse插件快速生成ssh项目并配置注解 在action层注入service的超详细过程
最近发现,我对于ssh的 自动注入配置 还是不熟悉,于是整理了一下 终于做了一个 简单的 注入配置出来. 以前都是在applicationContext.xml 里面这样配 <bean id=& ...
- Spring Boot入门-快速搭建web项目
Spring Boot 概述: Spring Boot makes it easy to create stand-alone, production-grade Spring based Appli ...
- 快速搭建Vue项目
快速搭建Vue项目 第一次安装vue项目Vue推荐开发环境Node.js 6.2.0.npm 3.8.9.webpack 1.13.vue-cli 2.5.1.webstrom2016 安装环境: 安 ...
- 在线官网Spring Initializr 或 IntelliJ IDEA 快速搭建springboot项目
Spring Boot是由Pivotal团队提供的全新框架,设计目的是用来简化新Spring应用的初始搭建以及开发过程.它主要推崇的是'消灭配置’,实现零配置. 那么,如何快速新建一个一个spring ...
- (05节)快速搭建SSM项目
1.1 快速搭建Web项目 注意点:name:archetypeCatalog,value:internal 原因:Intellij IDEA根据maven archetype的本质,执行mvn a ...
- 小D课堂-SpringBoot 2.x微信支付在线教育网站项目实战_2-2.快速搭建SpringBoot项目,采用IDEA
笔记 2.快速搭建SpringBoot项目,采用IDEA 简介:使用SpringBoot start在线生成项目基本框架并导入到IDEA中 参考资料: IDEA使用文档 ...
- 小D课堂-SpringBoot 2.x微信支付在线教育网站项目实战_2-1.快速搭建SpringBoot项目,采用Eclipse
笔记 1.快速搭建SpringBoot项目,采用Eclipse 简介:使用SpringBoot start在线生成项目基本框架并导入到eclipse中 1.站点地址:http://start. ...
- 使用IDEA快速搭建Springboot项目
Spring Boot是由Pivotal团队提供的全新框架,设计目的是用来简化新Spring应用的初始搭建以及开发过程.它主要推崇的是'消灭配置’,实现零配置. 下面就介绍一下如何使用idea快速搭建 ...
随机推荐
- Prometheus初体验(三)
一.安装部署 Prometheus基于Golang编写,编译后的软件包,不依赖于任何的第三方依赖.用户只需要下载对应平台的二进制包,解压并且添加基本的配置即可正常启动Prometheus Server ...
- 第K个幸运数(京东2017秋招真题)
题目 4和7是两个幸运数字,我们定义,十进制表示中,每一位只有4和7两个数的正整数都是幸运数字.前几个幸运数字为:4,7,44,47,74,77,444,447... 现在输入一个数字K,输出第K个幸 ...
- argmin ,argmax函数
在数学中,ARG MAX(或ARGMAX)代表最大值,即给定参数的点集,给定表达式的值达到其最大值: 换一种说法, 是f(x)具有最大值M的x的值的集合.例如,如果f(x)是1- | x |,那么它在 ...
- 【纸模】六角大王 Super 5.6 CHS 简体中文版 U20080725+[手册]窗口与工具的概要(PDF格式)
六角大王5.6简体中文版中文化:star21 主界面<ignore_js_op> 人体生成模式<ignore_js_op> 动画<ignore_js_op> < ...
- Vue 使用axios分片上传
Vue的界面 <input type="file"/> 上传方法 fileUpload: function () { var num = 1 var file = do ...
- MQTT教學(一):認識MQTT
http://swf.com.tw/?p=1002 本系列文章旨在補充<超圖解物聯網IoT實作入門>,採用Arduino.ESP8266和Node.js實作MQTT物聯網通訊實驗. MQT ...
- sanity checking
https://zh.wikipedia.org/wiki/健全性测试 Modules\_threadmodule.c /* Lock objects */ typedef struct { PyOb ...
- shell编程系列11--文本处理三剑客之sed利用sed删除文本中的内容
shell编程系列11--文本处理三剑客之sed利用sed删除文本中的内容 删除命令对照表 命令 含义 1d 删除第一行内容 ,10d 删除1行到10行的内容 ,+5d 删除10行到16行的内容 /p ...
- Web Service 和 WCF的比较
Web Service 和WCF的比较 Web Service 的工作原理 Web Service也叫XML Web Service WebService是一种可以接收从Internet或者Intra ...
- ASP将Table导出Excel
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%><%if request("action") ...