文件夹结构:

搭建项目:

1.创建web项目

2.创建各种包.

com.atguigu.surveypark.dao.impl

com.atguigu.surveypark.model

com.atguigu.surveypark.service.impl

com.atguigu.surveypark.struts2.action

com.atguigu.surveypark.util

3.引入类库

[struts2]

asm-3.3.jar

asm-commons-3.3.jar

asm-tree-3.3.jar

commons-fileupload-1.3.jar

commons-io-2.0.1.jar

commons-lang3-3.1.jar

commons-logging-1.1.3.jar

freemarker-2.3.19.jar

javassist-3.11.0.GA.jar

log4j-1.2.17.jar

ognl-3.0.6.jar

struts2-core-2.3.15.1.jar

xwork-core-2.3.15.1.jar





[hibernate]

antlr-2.7.7.jar

hibernate-commons-annotations-4.0.2.Final.jar

hibernate-core-4.2.3.Final.jar

hibernate-entitymanager-4.2.3.Final.jar

hibernate-jpa-2.0-api-1.0.1.Final.jar

javassist-3.15.0-GA.jar

hibernate-ehcache-4.2.3.Final.jar





[spring]

org.springframework.aop-3.1.0.CI-1162.jar

org.springframework.asm-3.1.0.CI-1162.jar

org.springframework.aspects-3.1.0.CI-1162.jar

org.springframework.beans-3.1.0.CI-1162.jar

org.springframework.context-3.1.0.CI-1162.jar

org.springframework.context.support-3.1.0.CI-1162.jar

org.springframework.core-3.1.0.CI-1162.jar

org.springframework.expression-3.1.0.CI-1162.jar

org.springframework.jdbc-3.1.0.CI-1162.jar

org.springframework.orm-3.1.0.CI-1162.jar

org.springframework.transaction-3.1.0.CI-1162.jar

org.springframework.web-3.1.0.CI-1162.jar





com.springsource.net.sf.cglib-2.2.0.jar

com.springsource.org.aopalliance-1.0.0.jar

com.springsource.org.aspectj.tools-1.6.6.RELEASE.jar

com.springsource.org.aspectj.weaver-1.6.8.RELEASE.jar

[struts2-spring插件]

struts2-spring-plugin-2.3.15.1.jar

[数据源]

com.springsource.com.mchange.v2.c3p0-0.9.1.2.jar

[驱动程序]

mysql-connector-java-5.0.8-bin.jar

3.配置项目

[struts2 + web]

[web-inf/web.xml]

<!-- 配置struts2的过滤器 -->

<filter>

<filter-name>action</filter-name>

<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>

</filter>

<filter-mapping>

<filter-name>action</filter-name>

<url-pattern>/*</url-pattern>

</filter-mapping>

[confi/struts.xml]

<?xml version="1.0"?>

<!DOCTYPE struts PUBLIC

"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"

"http://struts.apache.org/dtds/struts-2.3.dtd">

<struts>

<package name="surveyparkPkg" extends="struts-default" namespace="/">



</package>

</struts>

[spring--config/beans.xml]

由图的依赖可知:应该先配置数据源。配置数据源之前能够先创建数据库。

1.创建数据库:lsn_surveypark001

2.配置config/bean.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:aop="http://www.springframework.org/schema/aop"

xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"

xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd

http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.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">



<!-- 分散配置 -->

<context:property-placeholder location="classpath:jdbc.properties"/>



<!-- 配置数据源 -->

<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">

<property name="driverClass" value="${jdbc.driverclass}" />

<property name="jdbcUrl" value="${jdbc.url}" />

<property name="user" value="${jdbc.username}" />

<property name="password" value="${jdbc.password}" />



<property name="maxPoolSize" value="${c3p0.pool.size.max}" />

<property name="minPoolSize" value="${c3p0.pool.size.min}" />

<property name="initialPoolSize" value="${c3p0.pool.size.ini}" />

<property name="acquireIncrement" value="${c3p0.pool.size.increment}" />

</bean>

</beans>





[jdbc.properties]

jdbc.driverclass=com.mysql.jdbc.Driver

jdbc.url=jdbc:mysql://locallhost:3306/lsn_surveypark001

jdbc.username=root

jdbc.password=root





c3p0.pool.size.max=10

c3p0.pool.size.min=2

c3p0.pool.size.ini=3

c3p0.pool.size.increment=2

4.測试数据源

public class TestDataSource {

@Test

public void getConnection() throws SQLException{

ApplicationContext ac = new ClassPathXmlApplicationContext("beans0.xml");

DataSource ds = (DataSource) ac.getBean("dataSource");

System.out.println(ds.getConnection());

}

}

配置config/beans0.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:aop="http://www.springframework.org/schema/aop"

xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"

xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd

http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.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">



<!-- 分散配置 -->

<context:property-placeholder location="classpath:jdbc.properties"/>

<context:component-scan base-package="com.atguigu.surveypark.dao.impl,com.atguigu.surveypark.service.impl,com.atguigu.surveypark.struts2.action" />



<!-- 配置数据源 -->

<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">

<property name="driverClass" value="${jdbc.driverclass}" />

<property name="jdbcUrl" value="${jdbc.url}" />

<property name="user" value="${jdbc.username}" />

<property name="password" value="${jdbc.password}" />



<property name="maxPoolSize" value="${c3p0.pool.size.max}" />

<property name="minPoolSize" value="${c3p0.pool.size.min}" />

<property name="initialPoolSize" value="${c3p0.pool.size.ini}" />

<property name="acquireIncrement" value="${c3p0.pool.size.increment}" />

</bean>



<!-- 本地回话工厂bean(spring整合hibernate的核心入口) -->

<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">

<property name="dataSource" ref="dataSource" />

<property name="configLocation" value="classpath:hibernate.cfg.xml" />

<property name="mappingDirectoryLocations">

<list>

<value>classpath:com/atguigu/surveypark/model</value>

</list>

</property>

</bean>



<!-- hibnerate事务管理器,用来在service层面上实现事务管理,并且达到平台无关性 -->

<bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">

<property name="sessionFactory" ref="sessionFactory" />

</bean>



<!-- 事务通知 -->

<tx:advice id="txAdvice" transaction-manager="txManager">

<tx:attributes>

<!-- 写操作 -->

<tx:method name="save*" propagation="REQUIRED" isolation="DEFAULT"/>

<tx:method name="update*" propagation="REQUIRED" isolation="DEFAULT"/>

<tx:method name="delete*" propagation="REQUIRED" isolation="DEFAULT"/>

<tx:method name="batch*" propagation="REQUIRED" isolation="DEFAULT"/>



<!-- 读操作 -->

<tx:method name="load*" propagation="REQUIRED" isolation="DEFAULT" read-only="true"/>

<tx:method name="get*" propagation="REQUIRED" isolation="DEFAULT" read-only="true"/>

<tx:method name="find*" propagation="REQUIRED" isolation="DEFAULT" read-only="true"/>



<tx:method name="*" propagation="REQUIRED" isolation="DEFAULT"/>

</tx:attributes>

</tx:advice>



<!-- aop配置 -->


<aop:config>

<aop:advisor advice-ref="txAdvice" pointcut="execution(* *..*Service.*(..))"/>

</aop:config>

</beans>

測试插入用户

public class TestUserService {



private static UserService us ;





@BeforeClass

public static void iniUserService(){

ApplicationContext ac = new ClassPathXmlApplicationContext("beans0.xml");

us = (UserService) ac.getBean("userService");

}

/**

* 插入用户 

*/

@Test

public void insertUuser() throws SQLException{

User u = new User();

u.setEmail("xupccc@hotmail.com");

u.setPassword("123456");

u.setNickName("stone");

us.saveEntity(u);

}

}

版权声明:本文博客原创文章,博客,未经同意,不得转载。

ssh 综合的更多相关文章

  1. SSH综合练习-仓库管理系统-第二天

    SSH综合练习-仓库管理系统-第二天 今天的主要内容: 货物入库 页面信息自动补全回显功能:(学习目标:练习Ajax交互) 根据货物简记码来自动查询回显已有货物(Ajax回显) 根据货物名来自动查询补 ...

  2. SSH综合练习-第1天

    SSH综合练习-仓库管理系统-第一天 综合练习的整体目的: 整合应用 Struts2 .Hibernate.Spring .Mysql . jQuery Ajax.java基础知识 熟悉企业SSH 基 ...

  3. 分享知识-快乐自己:SSH 整合 Demo

    楼主A: XML 版 SSH整合Demo https://github.com/MlqBeginner/BlogGardenWarehouse/blob/master/SSH%E6%95%B4%E5% ...

  4. 终于,我还是下决心学Java后台了

    我没有什么本事,人也丑,也不会忽悠,只能硬着头皮学习了.最近计划学习Java后台,因为最近接了私活的问题,好多都要Java后台和前端一起做.平常我在做什么,当然是忙着赚钱了 除了敲代码,你还有什么副业 ...

  5. java 后台的学习步骤

    一.JavaWeb部分 第一阶段:JavaWeb前端技术 web前端技术 HTML, CSS, JavaScript基础, jQuery基础, BootStrap. 第二阶段:服务器端技术 Mysql ...

  6. 项目:《ssh框架综合项目开发视频》-视频目录和第六天的EasyUI简单讲解

    4 练习使用技术: Struts2 + hibernate5.x + spring4.x + mysql数据库 1 crm:customer relational manager,客户关系管理 2 c ...

  7. Windows上安装配置SSH教程(8)——综合应用:在Windows上使用手动方式实现SSH远程登陆与文件传输

    服务器端操作系统:Windows XP 客户端操作系统:Windows10 安装与配置顺序 1.服务端安装OpenSSH 2.服务端配置OpenSSH 3.客户端安装OpenSSH 4.客户端安装Wi ...

  8. Windows上安装配置SSH教程(6)——综合应用:在Windows上实现SSH远程登陆与文件传输

    ----------------- 声明:本教程现已经弃用.由于客户端同时安装Cygwin和OpenSSH for Windows会出现问题(Cygwin的shell下无法使用ssh命令),建议直接在 ...

  9. Jenkins结合.net平台综合应用之通过SSH方式拉取代码

    上一节我们讲解了如何Jenkins如何通过轮训来监听git仓库变化然后拉取最新代码,上一节中我们使用的是https方式,然后正式环境中企业更倾向使用ssh方式.这里我们讲解一下如何通在Jenkins中 ...

随机推荐

  1. UVA 1546 - Complete the sequence!(差分法)

    UVA 1546 - Complete the sequence! 题目链接 题意:给定多项式前s项,求出后c项,要求尽量小 思路:利用差分法,对原序列求s - 1次差分,就能够发现规律,然后对于每多 ...

  2. 利用Eclipse中的Maven构建Web项目(三)

    利用Eclipse中的Maven构建Web项目 1.将Maven Project转换成动态Web项目,鼠标右键项目,输入"Project Facets" 2.依据Dynamic W ...

  3. UVA 11402 - Ahoy, Pirates!(段树)

    UVA 11402 - Ahoy, Pirates! 题目链接 题意:总的来说意思就是给一个01串,然后有3种操作 1.把一个区间变成1 2.把一个区间变成0 3.把一个区间翻转(0变1,1变0) 思 ...

  4. Java他们其中一个IO(一)

    1.I/O 操作的目标 其中从数据源读取数据,和写数据到的目标位置数据. 2.IO 的分类方法 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxMTc ...

  5. Java的λ表达(lambda)

    λ表达的基本目的 回调Java8的λ表达式 说明了Java8的λ表达式的基本用途:完毕了回调的原意--代码的參数化. 回调:能够简单地说,假设你的方法须要override底层或JDK的某个类的方法,并 ...

  6. 探索Windows Azure 监控和自动伸缩系列3 - 启用Azure监控扩展收集自定义监控数据

    上一篇我们介绍了获取Azure的监控指标和监控数据: http://www.cnblogs.com/teld/p/5113376.html 本篇我们继续:监控虚拟机的自定义性能计数器. 随着我们应用规 ...

  7. 成不了天才,但为何也没成"人材"?(转)

    长期以来,"软件业"一直被视为"智力密集"型的"朝阳"产业,大多数从业者都受过高等教育,其平均素质居于社会各行业的前列,这个产业的顶尖人物被 ...

  8. Paypal-Express Checkout快捷支付方式的android端开发心得(二)

    一.前导 上一篇讲的不是非常好,这里再又一次讲一下. Paypal手机支付有2种形式: 1.Mobile Express Checkout,MEC,快捷支付 2.MPL 假设採用MEC支付方式,这样的 ...

  9. jquery:ajax不接收返回值回

    html页面a加元素的假设href=javasrcipt:void(0)会导致ajax没有收到回后台值. : <p class="chatmsg_load_more"> ...

  10. Java多线程&lt;1&gt;

    1.Java多线程的概念: 线(Thread):它指的是一个任务的从开始执行流程到结束. 穿线提供执行任务的机构.供java条款.在一个程序可以启动多个并发线程.候执行. 在单处理器系统中,多个线程共 ...