SSM框架整合基本操作
1.首先导入各种需要的配置包,在这里个人的习惯就是先导入mybatis相关包,然后通过编程软件集成一个spring3.0或者spring3.1进来并选择里面相应的包,这样就不需要我们自己去导入相应的spring包了。
2.新建spring-mybatis.xml文件以及spring-mvc.xml文件,分别配置如下:
spring-mybatis.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:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd
">
<!-- 采用注释的方式配置bean -->
<context:annotation-config />
<!-- 配置要扫描的包 -->
<context:component-scan base-package="com.julong.testoracle" /> <!-- 分解配置 jdbc.properites -->
<context:property-placeholder location="classpath:jdbc.properties" />
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${jdbc.driverClassName}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
<!-- 队列中的最小等待数 -->
<property name="minIdle" value="${jdbc.minIdle}"></property>
<!-- 队列中的最大等待数 -->
<property name="maxIdle" value="${jdbc.maxIdle}"></property>
<!-- 最长等待时间,单位毫秒 -->
<property name="maxWait" value="${jdbc.maxWait}"></property>
<!-- 最大活跃数 -->
<property name="maxActive" value="${jdbc.maxActive}"></property>
<property name="initialSize" value="${jdbc.initialSize}"></property>
</bean> <!-- spring和MyBatis完美整合,不需要mybatis的配置映射文件 -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<!-- 自动扫描mapping.xml文件 -->
<property name="mapperLocations" value="classpath:com/julong/testoracle/mapper/*.xml"></property>
</bean> <!-- DAO接口所在包名,Spring会自动查找其下的类 -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.julong.testoracle.dao"> </property>
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>
</bean> <!-- (事务管理)transaction manager, use JtaTransactionManager for global tx -->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
</beans>
spring-mvc.xml配置文件
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd">
<!-- 配置需要用过mvc监听的文件 -->
<context:component-scan base-package="com.julong.testoracle.controller" /> </beans>
3.配置相应的web.xml文件如下:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
<display-name>oracle</display-name>
<!-- spring的监听器 -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener> <!--全局范围内环境参数初始化,即初始化spring-mybatis.xml-->
<context-param>
<param-name>contextConfigLocation</param-name> <!--参数名称-->
<param-value>classpath:spring-mybatis.xml</param-value><!--参数取值-->
</context-param> !--用来声明一个servlet的数据 -->
<servlet>
<servlet-name>springMVC</servlet-name><!--指定servlet的名称-->
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class><!--指定servlet的类名称,这里配置了前端控制器-->
<init-param>
<param-name>contextConfigLocation</param-name><!--参数名称-->
<param-value>classpath:spring-mvc.xml</param-value><!--参数值-->
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>springMVC</servlet-name> <!--指定servlet的名称-->
<url-pattern>*.mvc</url-pattern> <!--指定servlet所对应的URL-->
</servlet-mapping> <!-- 编码过滤器 -->
<filter>
<filter-name>CharacterEncodingFilter</filter-name>
<filter-class>
org.springframework.web.filter.CharacterEncodingFilter
</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CharacterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
4.指定数据库连接时需要引入的资源文件(因前面给其分解开来了)
#jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.driverClassName=oracle.jdbc.OracleDriver
#jdbc.url=jdbc:mysql://localhost:3306/operationLog
jdbc.url=jdbc:oracle:thin:@127.0.0.1:1521:orcl
#jdbc.url=jdbc:oracle:thin:@192.168.1.111:1521:orcl
jdbc.username=oracle
jdbc.password=oracle
#jdbc.password=root
jdbc.maxActive = 2
jdbc.maxIdle =5
jdbc.minIdle=1
jdbc.initialSize =3
jdbc.maxWait =3000
SSM框架整合基本操作的更多相关文章
- SSM框架整合项目 :租房管理系统
使用ssm框架整合,oracle数据库 框架: Spring SpringMVC MyBatis 导包: 1, spring 2, MyBatis 3, mybatis-spring 4, fastj ...
- 基于maven的ssm框架整合
基于maven的ssm框架整合 第一步:通过maven建立一个web项目. 第二步:pom文件导入jar包 (1 ...
- JavaWeb之ssm框架整合,用户角色权限管理
SSM框架整合 Spring SpringMVC MyBatis 导包: 1, spring 2, MyBatis 3, mybatis-spring 4, fastjson 5, aspectwea ...
- SSM框架整合环境构建——基于Spring4和Mybatis3
目录 环境 配置说明 所需jar包 配置db.properties 配置log4j.properties 配置spring.xml 配置mybatis-spring.xml 配置springmvc.x ...
- springmvc(二) ssm框架整合的各种配置
ssm:springmvc.spring.mybatis这三个框架的整合,有耐心一步步走. --WH 一.SSM框架整合 1.1.整合思路 从底层整合起,也就是先整合mybatis与spring,然后 ...
- SSM框架整合的其它方式
---------------------siwuxie095 SSM 框架整合的其它方式 1.主要是整合 Spring ...
- SSM框架整合过程总结
-----------------------siwuxie095 SSM 框架整合过程总结 1.导入相关 jar 包( ...
- SSM框架整合思想
-------------------siwuxie095 SSM 框架整合思想 1.SSM 框架,即 SpringMV ...
- SSM框架整合搭建教程
自己配置了一个SSM框架,打算做个小网站,这里把SSM的配置流程详细的写了出来,方便很少接触这个框架的朋友使用,文中各个资源均免费提供! 一. 创建web项目(eclipse) File-->n ...
随机推荐
- oracle删除表的方法
1. 删除oracle表中的所有数据而不删除表: 语法: TRUNCATE TABLE table_name; 使用这条语句只是删除表中的全部数据,不是删除表,这种方式也叫做截断表,这种方式比使用de ...
- BZOJ 3944 Sum 解题报告
我们考虑令: \[F_n = \sum_{d|n}\varphi(d)\] 那么,有: \[\sum_{i=1}^{n}F_i = \sum_{i=1}^{n}\sum_{d|i}\varphi(d) ...
- dorado7第一次使用感受
今天第一次玩dorado,说一下使用的感受 1.首先是优点: 首先是它的学习文档非常丰富,视频,PDF,PPT,实例,社区一应俱全 界面风格已经帮我们做完,无需担心界面美观的问题 与后台交互非常方便, ...
- codeforces 390C Inna and Candy Boxes
这个题目看似不是很好下手,不过很容易发现每次询问的时候总是会问到第r个盒子是否有糖果: 这样的话就很好办事了: 维护两个数组: 一个sum数组:累加和: 一个in数组:如果i位是1的话,in[i]=i ...
- Javascript与C#相互调用
javascript调用C#代码 前台js调用后台代码方法,此方法只适用于后台方法的修饰符为public或protected,如果是其他修饰符会报错. >后台C#代码: protected in ...
- TSS 内核栈 用户栈的关系
http://blog.sina.com.cn/s/blog_673ef8130100qaje.html 该博客不错,有不少有用的信息 中断程序的一开始我们执行一个PUSHALL,把这些积存器保存在核 ...
- poj3373Changing Digits(dp)
链接 dfs倒着搜 返回的路径不能满足相同的数最多 借鉴了下别人的代码.. 先dp出来 再倒着标记一下 然后正回来一定可以满足了 dp保存的是最小的不相同数 #include <iostream ...
- Apache Struts ClassLoader操作漏洞
漏洞版本: Apache Struts 2.x 漏洞描述: CVE ID:CVE-2014-0094 Struts2 是第二代基于Model-View-Controller (MVC)模型的java企 ...
- C# VS2010中,用微软自带的System.Data.OracleClient来连接Oracle数据库
由于微软在.Net框架4.0中已经决定撤销使用System.Data.OracleClient,造成在VS2010中无法连接Oracle数据库,但它还依旧存在于.Net架构中,我们可以通过自己引用 C ...
- LittleTools之网格输出为模型
我经常要在Unity中生成一些网格,但是这些网格需要交给美工修改,所以又要将网格输出为模型.于是就有了下面的代码: using UnityEngine; using UnityEditor; usin ...