首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

SSH调整方案2

2013-09-11 
SSH整合方案2【案例3】SSH整合_方案2 ** 案例描述 两个知识点的演示 其一,SSH整合的第二个方案 其二,SpringJ

SSH整合方案2
【案例3】SSH整合_方案2 ** 
案例描述 
两个知识点的演示 
其一,SSH整合的第二个方案 
其二,Spring+JDBC+Struts2 
参考代码 
31) 使用工程spring4 
32) 修改ssh.xml 
增加<bean name="loginAction"> 

<?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:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"> <bean id="myDataSource" class="org.apache.commons.dbcp.BasicDataSource"> <property name="driverClassName" value="com.mysql.jdbc.Driver"></property> <property name="url" value="jdbc:mysql:///test"></property> <property name="username" value="root"></property> <property name="password" value="root"></property> <property name="maxActive" value="10"></property> <property name="initialSize" value="2"></property> </bean> <!--注释掉Hibernate配置的bean SessionFactory--> <!-- <bean id="mySessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">  <property name="dataSource" ref="myDataSource"></property> <property name="mappingResources"> <list> <value>tarena/mapping/User.hbm.xml</value> </list> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect"> org.hibernate.dialect.MySQL5Dialect</prop> <prop key="hibernate.show_sql">true</prop> <prop key="hibernate.format_sql">true</prop> </props> </property> </bean> <bean id="userDao" class="tarena.dao.impl.HibernateUserDAOImpl"> <property name="sessionFactory" ref="mySessionFactory"></property> </bean> <bean id="userService" class="tarena.service.impl.UserServiceImpl"> <property name="userDao" ref="userDao"></property> </bean> --> <bean id="jdbcUserDao" class="tarena.dao.impl.JdbcUserDAOImpl"> <property name="dataSource" ref="myDataSource"></property> </bean> <bean id="userService" class="tarena.service.impl.UserServiceImpl"> <property name="userDao" ref="jdbcUserDao"></property> </bean> <bean id="loginAction" class="tarena.action.LoginAction"> <property name="userService" ref="userService"></property> </bean>  <!-- 声明式事务控制 --> <!-- <bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory" ref="mySessionFactory"></property> </bean> --> <bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="myDataSource"></property> </bean> <tx:advice id="txAdvice" transaction-manager="txManager"> <tx:attributes> <tx:method name="save*" propagation="REQUIRED"/> <tx:method name="update*" propagation="REQUIRED"/> <tx:method name="delete*" propagation="REQUIRED"/> <tx:method name="find*" read-only="true" propagation="NOT_SUPPORTED"/> <tx:method name="*" propagation="REQUIRED"/> </tx:attributes> </tx:advice> <aop:config> <aop:pointcut expression="within(tarena.service..*)" id="servicePointcut"/> <aop:advisor advice-ref="txAdvice" pointcut-ref="servicePointcut"/> </aop:config> </beans> 


38) 测试(略) 
在编写程序的过程中,会调试大量的Exception,使用System.out.println()是一种简便的方法。 
另外,MyEclipse还提供了调试程序的Debug工具 
Debug工具演示 
假设,我们现在想跟踪JdbcUserDAOImpl中的实现方法findByEmail, 
首先,设置调试断点, 
在需要跟踪的代码处双击“序号前面”,将出现一个蓝色小点, 
其次,设置tomcat为debug模式 
开始调试 
访问http://localhost:/8080/spring4/login.jsp 
点击“登录”按钮 
此时,MyEclipse工具将弹出对话框询问是否打开“Debug”视图,选择“Yes” 
从“show view”中打开也一样 
 整个Debug视图由如下几部分组成 
此时,程序停在了这里 
点击“Run”选项,就有许多快捷键 
 使用说明 
按键 
快捷键 
功能 
Resume 
F8 
表示从当前断点处,继续向下执行,即放弃当前断点,直接向下执行(如果有多个断点,则停在下一个断点处) Step Over 
F6 
表示从当前设置断点处的代码向下,一行一行执行 Step Into 
F5 
如果当前设置断点代码处,调用了子方法, 
比如String s = foo.findAll(); 
当想迚入到该子方法findAll()当中去时,就可以点击F5 
Step Return 
F7 
万一丌小心跳入到别的方法中,该快捷点可以再跳出来,回到上一级 
一般情冴下,如果设置断点处,有自定义的方法,那么就可以按F5 Step Into跟迚, 
如果是JDK戒者框架提供的方法,那就按F6,直接执行下一行代码即可。 
当断点调试程序结束,如果想取消设置的断点,可以在断点的蓝色小点上再双击一下就取消了。 
也可以打开BreakPoint视图, 
将checkBox前的对勾去掉即可(如果设置了多个断点时,好用)



热点排行