最近学习了ibatis,感觉要比hibernate更加灵活(我个人意见),整理一下,我用的是oracle数据库,其它的就不说了,直接奔主题,把在框架中需要用到的配置文件的相关内容做个简单的介绍。
(一)、下载所需要的框架的架包,各个官方网站直接下载。
(二)、修改web.xml文件,在里面加入如下内容:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<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>
(三)、对struts.xml文件的配置:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<constant name="struts.objectFactory" value="spring" />
<package name="struts2" extends="struts-default">
<!-- 自己需要的相关action信息 -->
</package>
</struts>
(四)、对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:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
<property name="url" value="jdbc:oracle:thin:@xxx.xxx.xxx.xxx:1521:datebaseName" />
<property name="username" value="username" />
<property name="password" value="password" />
</bean>
<bean id="client" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="dataSource">
<ref local="dataSource"/>
</property>
<property name="configLocation">
<value>classpath:SqlMapConfig.xml</value>
</property>
</bean>
<!-- 实际程序中需要注入的bean -->
</beans>
(五)、SqlMapConfig.xml文件中的相关内容:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sqlMapConfig
PUBLIC "-//ibatis.apache.org//DTD SQL Map Config 2.0//EN"
"http://ibatis.apache.org/dtd/sql-map-config-2.dtd">
<sqlMapConfig>
<sqlMap resource="对应的xml配置文件的位置"/>
</sqlMapConfig>
以上只是简单的配置文件的相关信息,希望帮到你!