SSH 配置文件
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: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-2.5.xsdhttp://www.springframework.org/schema/context?http://www.springframework.org/schema/context/spring-context-2.5.xsdhttp://www.springframework.org/schema/tx?http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"><!--?自動(dòng)掃描與裝配bean?--><context:component-scan?base-package="cn.itcast.oa"></context:component-scan><!--?導(dǎo)入外部的properties文件?--><context:property-placeholder?location="classpath:jdbc.properties"/><!--?配置SessionFactory?--><bean?id="sessionFactory"?class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"><!--?指定hibernate的配置文件位置?--><property?name="configLocation"?value="classpath:hibernate.cfg.xml"></property><!--?配置c3p0數(shù)據(jù)庫(kù)連接池?--><property?name="dataSource"><bean?class="com.mchange.v2.c3p0.ComboPooledDataSource"><!--?數(shù)據(jù)連接信息?--><property?name="jdbcUrl"?value="${jdbcUrl}"></property><property?name="driverClass"?value="${driverClass}"></property><property?name="user"?value="${user}"></property><property?name="password"?value="${password}"></property><!--?其他配置?--><!--初始化時(shí)獲取三個(gè)連接,取值應(yīng)在minPoolSize與maxPoolSize之間。Default:?3?--><property?name="initialPoolSize"?value="3"></property><!--連接池中保留的最小連接數(shù)。Default:?3?--><property?name="minPoolSize"?value="3"></property><!--連接池中保留的最大連接數(shù)。Default:?15?--><property?name="maxPoolSize"?value="5"></property><!--當(dāng)連接池中的連接耗盡的時(shí)候c3p0一次同時(shí)獲取的連接數(shù)。Default:?3?--><property?name="acquireIncrement"?value="3"></property><!--?控制數(shù)據(jù)源內(nèi)加載的PreparedStatements數(shù)量。如果maxStatements與maxStatementsPerConnection均為0,則緩存被關(guān)閉。Default:?0?--><property?name="maxStatements"?value="8"></property><!--maxStatementsPerConnection定義了連接池內(nèi)單個(gè)連接所擁有的最大緩存statements數(shù)。Default:?0?--><property?name="maxStatementsPerConnection"?value="5"></property><!--最大空閑時(shí)間,1800秒內(nèi)未使用則連接被丟棄。若為0則永不丟棄。Default:?0?--><property?name="maxIdleTime"?value="1800"></property></bean></property></bean><!--?配置聲明式事務(wù)管理(采用注解的方式)?--><bean?id="txManager"?class="org.springframework.orm.hibernate3.HibernateTransactionManager"><property?name="sessionFactory"?ref="sessionFactory"></property></bean><tx:annotation-driven?transaction-manager="txManager"/></beans> |
hibernate.cfg.xml
<?xml?version="1.0"?encoding="UTF-8"?> <!DOCTYPE?hibernate-configuration?PUBLIC"-//Hibernate/Hibernate?Configuration?DTD?3.0//EN""http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> <hibernate-configuration><session-factory><!--?數(shù)據(jù)庫(kù)連接信息?--><!--?<property?name="connection.url">jdbc:mysql://localhost:3306/ItcastOA</property><property?name="connection.username">root</property><property?name="connection.password">123</property><property?name="connection.driver_class">com.mysql.jdbc.Driver</property>?--><!--?Hibernate配置信息?--><!--?dialect方言--><property?name="dialect">org.hibernate.dialect.MySQLDialect</property><property?name="javax.persistence.validation.mode">none</property>?<!--?其他配置?--><property?name="hibernate.show_sql">true</property><property?name="hbm2ddl.auto">update</property><!--?在配置文件中關(guān)聯(lián)映射文件?--><mapping?resource="cn/itcast/oa/domain/User.hbm.xml"?/>?<mapping?resource="cn/itcast/oa/domain/Role.hbm.xml"?/>?<mapping?resource="cn/itcast/oa/domain/Department.hbm.xml"?/>?</session-factory> </hibernate-configuration>jdbc.properties
jdbcUrl =?jdbc:mysql://localhost:3306/ItcastOA driverClass =?com.mysql.jdbc.Driver user =?root password =123log4j.properties
###?direct?log?messages?to?stdout?### log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.Target=System.out log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE}?%5p?%c{1}:%L?-?%m%n###?direct?messages?to?file?hibernate.log?### #log4j.appender.file=org.apache.log4j.FileAppender #log4j.appender.file.File=hibernate.log #log4j.appender.file.layout=org.apache.log4j.PatternLayout #log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE}?%5p?%c{1}:%L?-?%m%n###?set?log?levels?-?for?more?verbose?logging?change?'info'?to?'debug'?###log4j.rootLogger=debug,?stdout#log4j.logger.org.hibernate=info #log4j.logger.org.hibernate=debug log4j.logger.org.cn.itcast.oa=debugstruts.xml
<?xml?version="1.0"?encoding="UTF-8"??> <!DOCTYPE?struts?PUBLIC"-//Apache?Software?Foundation//DTD?Struts?Configuration?2.0//EN""http://struts.apache.org/dtds/struts-2.0.dtd"><struts><!--?配置為開(kāi)發(fā)模式?--><constant?name="struts.devMode"?value="true"?/><!--?把擴(kuò)展名配置為action?--><constant?name="struts.action.extension"?value="action"?/><!--?把主題設(shè)置為simple?--><constant?name="struts.ui.theme"?value="simple"?/><package?name="default"?namespace="/"?extends="struts-default"><!--?配置測(cè)試用的ACTION(還未與Spring整合,class屬性寫類的全名)?--><!--?當(dāng)struts與spring整合之后,class屬性可以寫bean的名稱?--><action?name="test"?class="testAction"><result?name="success">/test.jsp</result></action><!--?崗位管理?--><action?name="role_*"?class="roleAction"?method="{1}"><result?name="list">?/WEB-INF/jsp/roleAction/list.jsp</result><result?name="saveRoleUI">?/WEB-INF/jsp/roleAction/saveRoleUI.jsp</result><result?name="toList"?type="redirectAction">role_list</result></action><!--?部門管理?--><action?name="department_*"?class="departmentAction"?method="{1}"><result?name="list">?/WEB-INF/jsp/departmentAction/list.jsp</result><result?name="showBypage">?/WEB-INF/jsp/departmentAction/list.jsp</result><result?name="saveDepartmentUI">?/WEB-INF/jsp/departmentAction/saveDepartmentUI.jsp</result><result?name="toList"?type="redirectAction">department_showBypage?parentId=${parentId}</result></action></package></struts>web.xml
| <?xml?version="1.0"?encoding="UTF-8"?> <web-app?version="3.0"?xmlns="http://java.sun.com/xml/ns/javaee"?xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"?xsi:schemaLocation="http://java.sun.com/xml/ns/javaee?http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"><display-name></display-name> <!--?配置Spring的用于初始化?--><listener><listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></listener><context-param><param-name>contextConfigLocation</param-name><param-value>classpath:applicationContext*.xml</param-value></context-param><!--?配置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><welcome-file-list><welcome-file>index.jsp</welcome-file></welcome-file-list> </web-app> |
Department.hbm.xml
<?xml?version="1.0"?><!DOCTYPE?hibernate-mapping?PUBLIC"-//Hibernate/Hibernate?Mapping?DTD?3.0//EN""http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"><hibernate-mapping?package="cn.itcast.oa.domain"><class?name="Department"?table="t_department"><id?name="id"><generator?class="native"?/></id><property?name="name"?/><property?name="description"?/><!--?users屬性?,本類與User?一對(duì)多?--><set?name="users"><key?column="departmentId"></key><one-to-many?class="User"?/></set><!--?parent屬性?,本類與Department(上級(jí))多對(duì)一?--><many-to-one?name="parent"?class="Department"?column="parentId"?lazy="false"></many-to-one><!--?children屬性?,本類與Department(下級(jí))一對(duì)多??級(jí)聯(lián)刪除--><set?name="children"?cascade="delete"?lazy="false"><key?column="parentId"></key><one-to-many?class="Department"?/></set></class></hibernate-mapping>轉(zhuǎn)載于:https://blog.51cto.com/zhengkeke/1417878
總結(jié)
- 上一篇: 你在用什么思想编码:事务脚本 OR 面向
- 下一篇: 30个Oracle语句优化规则详解