SSI框架整合-1

SSI框架整合

开发工具:

MyEclipse8.5

框架版本:

struts2、spring2.5、ibatis

打开MyEclipse8.5新建一个web project如图:



填写完项目名称后选择Java EE 5.0,点finish

然后开始添加spring支持如图:



选择spring2.5,这里的包默认就可以,因为到最后这些包我都会将之删除,因为jar包冲突所以我将不会使用MyEclipse里自带的包,这里我只要后边这个文件 如图:点next

将applicationContext.xml放在项目WebRoot/WEB-INF文件夹下,点finish


然后我将把导入的spring包删除


删除后,导入自己的包


点next


选择你要导入的spring的jar包,放在test/WebRoot/WEB-INF/lib/spring2.5.5目录下,这样就很方便我们查看自己导入的包,点finish

接下来,就该导入struts了,同上


选择struts2.1 和  /*


点finish。然后删除导入的struts包,引入自己的


点finish。


发现项目仍然有错,缺少dbcp包,所以引入commons-dbcp.jar。具体方法(也是以后缺少包怎样引入的方法) 如图:


OK,没错了。


加入ibatis jar包;

配置applicationContext.xml文件添加以下代码

[html]  view plain copy
  1. <!-- 引入参数配置文件 -->  
  2.   
  3.      <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">  
  4.   
  5.       <property name="locations">  
  6.   
  7.        <list>  
  8.   
  9.         <value>classpath:sqlMapping.properties</value>  
  10.   
  11.        </list>  
  12.   
  13.       </property>  
  14.   
  15.      </bean>    
  16.   
  17. <!-- 数据源配制 -->  
  18.   
  19.     <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">  
  20.   
  21.             <property name="driverClassName">  
  22.   
  23.                <value>${jdbc.driverClassName}</value>  
  24.   
  25.             </property>  
  26.   
  27.            <property name="url">  
  28.   
  29.               <value>${jdbc.url}</value>  
  30.   
  31.            </property>  
  32.   
  33.            <property name="username">  
  34.   
  35.               <value>${jdbc.username}</value>  
  36.   
  37.            </property>  
  38.   
  39.            <property name="password">  
  40.   
  41.               <value>${jdbc.password}</value>  
  42.   
  43.            </property>        
  44.   
  45.     </bean>     
  46.   
  47. <!-- 此处应注入ibatis配置文件,而非sqlMap文件,否则会出现“there is no statement.....异常” -->     
  48.   
  49.     <bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">   
  50.   
  51.            <property name="configLocation" >       
  52.   
  53.                 <value>classpath:SqlMapConfig.xml</value>           
  54.   
  55.             </property>       
  56.   
  57.          <property name="dataSource" ref="dataSource"/>  
  58.   
  59.     </bean>      

之后创建 sqlMapConfig.xml文件和sqlMapping.properties文件

sqlMapConfig.xml文件代码为:

[html]  view plain copy
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2.   
  3. <!DOCTYPE sqlMapConfig  
  4.   
  5. PUBLIC "-//iBATIS.com//DTD SQL Map Config 2.0//EN"  
  6.   
  7. "http://www.ibatis.com/dtd/sql-map-config-2.dtd">  
  8.   
  9. <sqlMapConfig>  
  10.   
  11.   <settings  
  12.   
  13.     cacheModelsEnabled="true"  
  14.   
  15.     enhancementEnabled="true"  
  16.   
  17.     lazyLoadingEnabled="true"  
  18.   
  19.     errorTracingEnabled="false"  
  20.   
  21.     maxRequests="32"  
  22.   
  23.     maxSessions="10"  
  24.   
  25.     maxTransactions="5"  
  26.   
  27.     useStatementNamespaces="false"  
  28.   
  29.     />  
  30.   
  31.   <sqlMap resource="com/naxl/oa/model/tb_User.xml" />  
  32.   
  33.   <sqlMap resource="com/naxl/oa/model/tb_Department.xml" />  
  34.   
  35. </sqlMapConfig>  

sqlMapping.properties文件代码为:

[html]  view plain copy
  1. jdbc.driverClassName=com.mysql.jdbc.Driver  
  2.   
  3. jdbc.url=jdbc:mysql://192.168.1.104:3306/naxloa  
  4.   
  5. jdbc.username=root  
  6.   
  7. jdbc.password=admin  

接下来就要配置web.xml了,在web.xml添加以下代码

[html]  view plain copy
  1. <!-- 配置Spring -->  
  2.   
  3.    <context-param>  
  4.   
  5.       <param-name>contextConfigLocation</param-name>  
  6.   
  7.       <param-value>/WEB-INF/applicationContext.xml</param-value>  
  8.   
  9.    </context-param>  
  10.   
  11.     
  12.   
  13.    <listener>  
  14.   
  15.         <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>  
  16.   
  17.     </listener>  
  18.   
  19. 如果你的web.xml文件中没有配置struts,则需添加如下代码  
  20.   
  21. <filter>  
  22.   
  23.     <filter-name>struts2</filter-name>  
  24.   
  25.     <filter-class>  
  26.   
  27.     org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter  
  28.   
  29.     </filter-class>  
  30.   
  31. <init-param>  
  32.   
  33.           <param-name>config</param-name>  
  34.   
  35.       <param-value>struts-default.xml,struts-plugin.xml,struts.xml</param-value>  
  36.   
  37.    
  38.   
  39.       </init-param>  
  40.   
  41.   </filter>  
  42.   
  43.   <filter-mapping>  
  44.   
  45.     <filter-name>struts2</filter-name>  
  46.   
  47.     <url-pattern>/*</url-pattern>  
  48.   
  49.   </filter-mapping>  

Struts.xml文件代码为:

[html]  view plain copy
  1. <?xml version="1.0" encoding="UTF-8" ?>  
  2.   
  3. <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">  
  4.   
  5. <struts>  
  6.   
  7.     <package name="default" extends="json-default">  
  8.   
  9.           
  10.   
  11.        <action name="" class="" method="">  
  12.   
  13.          <result name=""> </result>  
  14.   
  15.          <result name=""> </result>  
  16.   
  17.         </action>             
  18.   
  19.     </package>  
  20.   
  21. </struts>  

运行Tomcat检查配置的项目有没有错,如果有缺失jar包请自己添加;

SSI搭建完成接下来就要写代码程序;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值