国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

SSH整合

2019-11-14 10:05:31
字體:
來源:轉載
供稿:網友

第一步:引入所需jar 第二步:配置web.xml文件

<!-- struts2配置 --> <filter> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPRepareAndExecuteFilter</filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <!-- Spring配置 --> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:bean*.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener>

classpath:bean*.xml指定路徑下的文件 第三步:寫指定路徑下的文件 bean-action.xml bean-service.xml bean-dao.xml 首先配置bean-dao.xml: Dao配置 <bean id="studao" class="dao.stuDao"> <property name="sessionFactory" ref="sessionFactory"></property> </bean> 連接池 <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"> <property name="driverClass" value="net.sourceforge.jtds.jdbc.Driver"></property> <property name="jdbcUrl" value="jdbc:jtds:sqlserver://127.0.0.1:49593/mybysj;charset=gbk;SelectMethod=CURSOR"></property> <property name="user" value="sa"></property> <property name="passWord" value="sa123"></property> <property name="initialPoolSize" value="3"></property> <property name="maxPoolSize" value="15"></property> </bean> 配置sessionFactory <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="dataSource" ref="dataSource"></property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</prop> <prop key="hibernate.show_sql">true</prop> <prop key="hibernate.hbm1ddl.auto">update</prop> </props> </property> <property name="mappingLocations"> <list> <value>classpath:hbm/*.hbm.xml</value> </list> </property> </bean> 配置事物 <bean id="txMannger" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory"></property> </bean> 配置事物增強 <tx:advice id="txadvice" transaction-manager="txMannger"> <tx:attributes> <tx:method name="*" read-only="false"/> </tx:attributes> </tx:advice> 配置aop <aop:config> <aop:pointcut expression="execution(* service.*.*(..))" id="pt"/> <aop:advisor advice-ref="txadvice" pointcut-ref="pt"/> </aop:config> classpath:hbm/*.hbm.xml 指定這個路徑下的映射文件 這里配置連接池,sessionFactory,事物及增強,aop切點表達式

第五步:寫pojo和*.hbm.xml

public class Student { private String sid; private String name; private Integer age; private String address; public Student(){} public String getSid() { return sid; } public void setSid(String sid) { this.sid = sid; } public String getName() { return name; } public void setName(String name) { this.name = name; } public Integer getAge() { return age; } public void setAge(Integer age) { this.age = age; } public String getAddress() { return address; } public void setAddress(String address) { this.address = address; }}

student.hbm.xml:

<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN""http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"><hibernate-mapping> <class name="entity.Student" table="student"> <id name="sid" column="s_id"> </id> <property name="name" column="s_name" type="java.lang.String"/> <property name="age" column="s_age" /> <property name="address" column="s_address" type="java.lang.String"/> </class></hibernate-mapping>

第六步:寫bean-action.xml和bean-service.xml bean-action.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:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd"> <bean id="stuAction" class="action.stuAction"> <property name="stuservice" ref="stuservice"></property> </bean></beans>

bean-service.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:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd http://www.springframework.Forg/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd"> <bean id="stuservice" class="service.stuService"> <property name="studao" ref="studao"></property> </bean></beans>

第七步:寫struts.xml

<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN" "http://struts.apache.org/dtds/struts-2.3.dtd"><struts> <constant name="struts.enable.DynamicMethodInvocation" value="false" /> <constant name="struts.devMode" value="ture" /> <constant name="struts.ui.theme" value="simple" /> <constant name="struts.objectFactory.spring.autoWire" value="no" /> <package name="default" namespace="/" extends="struts-default"> <action name="stu" class="stuAction" method="inertStu"> <result name="success">text.jsp</result> </action> </package></struts>

整合完畢,在整合期間遇到各種問題,記錄一下: Session session = sessionFactory.getCurrentSession(); 用這個方法取session,不能用sessionFactory.getSeeion();因為連接池支持線程 還有就是一定要細心,測試的代碼要注釋掉,我忘了把 sessionFactory = new Configuration().configure().buildSessionFactory();注釋掉,老是報找不到hibernate.cf.xml文件,可是整合的時候沒有這個文件啊,所以以后一定要細心; 最后謝謝大家觀看。讓我們一起進步!


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 嘉黎县| 新平| 修水县| 吴旗县| 璧山县| 简阳市| 临沧市| 岳阳县| 嘉鱼县| 五华县| 句容市| 紫阳县| 独山县| 贵定县| 兰州市| 汝城县| 八宿县| 崇仁县| 盖州市| 囊谦县| 泸定县| 保山市| 杭锦后旗| 康乐县| 鹤庆县| 来宾市| 临猗县| 西安市| 卓资县| 浦东新区| 醴陵市| 天气| 金堂县| 郧西县| 宁陕县| 榕江县| 天祝| 定安县| 遵义县| 宁陵县| 富阳市|