麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

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

SSH整合

2019-11-14 08:43:32
字體:
來源:轉載
供稿:網友

第一步:引入所需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文件,可是整合的時候沒有這個文件啊,所以以后一定要細心; 最后謝謝大家觀看。讓我們一起進步!


上一篇:文章標題

下一篇:POJ-1816 撥鐘問題

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 免费国产自久久久久三四区久久 | 亚洲国产视频在线 | 中文字幕在线视频日本 | 色99久久| 亚洲精品一区二区三区大胸 | 九九热视频在线免费观看 | 日韩欧美动作影片 | 欧美成年人视频在线观看 | av在线影片 | 亚洲一区二区中文字幕在线观看 | 男人午夜小视频 | 国产精品一区在线免费观看 | 国产精品一区二区三区在线 | 深夜小视频在线观看 | 国产 视频 一区二区 | 久久久资源网 | 性看小视频 | 久草免费新视频 | 欧美日韩亚洲精品一区二区三区 | 亚洲第一黄色网 | 国产亚洲精品yxsp | 国产成人精品一区二区视频免费 | 黄色免费入口 | 黄色免费小视频网站 | 91久久国产露脸精品国产 | 国产精品久久久网站 | 狠狠久久伊人中文字幕 | 红杏网站永久免费视频入口 | 免费毛片在线视频 | 亚洲视频在线观看免费视频 | 双性帝王调教跪撅打屁股 | 爱逼爱操综合网 | 五月天堂婷婷 | 黄色特级片黄色特级片 | 日韩一级网站 | 国产一级桃视频播放 | 一区二区三区视频播放 | 99爱在线免费观看 | 高清国产午夜精品久久久久久 | 日本高清黄色片 | 国产午夜免费 |