Spring+SpringMVC+MyBatis整合配置
前端控制器 web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
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_2_5.xsd">
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list> <!-- 前端控制器 -->
<servlet>
<servlet-name>dispatcherServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring.xml</param-value>
</init-param> <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcherServlet</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping> <!-- 中文乱码过滤器 -->
<filter>
<filter-name>encodingFilter</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>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping> </web-app>
spring核心配置文件
<?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:jdbc="http://www.springframework.org/schema/jdbc"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:jpa="http://www.springframework.org/schema/data/jpa"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.2.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.2.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa-1.3.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.2.xsd" > <!-- 加载属性配置文件 -->
<util:properties id="db"
location="classpath:db.properties"/> <!-- 定义数据源 -->
<bean id="ds" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="#{db.driver}"/>
<property name="url" value="#{db.url}"/>
<property name="username" value="#{db.user}"/>
<property name="password" value="#{db.pwd}"/>
</bean> <!-- 定义SQLSessionFactoryBean组件 MyBatis连接数据库1-->
<bean id="sqlSessionFactoryBean" class="org.mybatis.spring.SqlSessionFactoryBean" >
<!-- 没有了MyBatis的主配置文件SqlMapConfig.xml -->
<!-- 需要指定连接资源 -->
<property name="dataSource" ref="ds"></property>
<!-- 需要指定映射文件 -->
<property name="mapperLocations" value="classpath:com/xms/entity/mapper/*.xml"></property>
</bean> <!-- 定义MapperScannerrConfigurer扫描组件MyBatis扫描dao包2 -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer" >
<!-- 指定Mapper接口扫描包 -->
<property name="basePackage" value="com.xms.dao" ></property>
<!-- 手动指定SqlSessionFactory对象 --> <!-- sqlSessionFactory属性可以不用指定,它会以Autowired方式自动注入 -->
<property name="sqlSessionFactory" ref="sqlSessionFactoryBean" ></property> <!-- 推荐使用注解方法 -->
<property name="annotationClass" value="com.xms.common.MyAnnontation" ></property> <!-- 接口方法 -->
<!-- <property name="markerInterface" value="com.xms.common.Myinterface" /> -->
</bean> <!-- 开启注解扫描 -->
<context:component-scan base-package="com.xms"/> <!-- 开启RequestMapping注解扫描 -->
<mvc:annotation-driven/> <!-- 定义视图解析器ViewResolver -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/"/>
<property name="suffix" value=".jsp"/>
</bean> <!-- 全局异常处理 -->
<bean class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
<property name="exceptionMappings">
<props>
<prop key="java.lang.Exception">error</prop>
</props>
</property>
</bean> </beans>
Spring+SpringMVC+MyBatis整合配置的更多相关文章
- SSM Spring +SpringMVC+Mybatis 整合配置 及pom.xml
SSM Spring +SpringMVC+Mybatis 配置 及pom.xml SSM框架(spring+springMVC+Mybatis) pom.xml文件 maven下的ssm整合配置步骤
- Spring+springmvc+Mybatis整合案例 xml配置版(myeclipse)详细版
Spring+springmvc+Mybatis整合案例 Version:xml版(myeclipse) 文档结构图: 从底层开始做起: 01.配置web.xml文件 <?xml version ...
- idea spring+springmvc+mybatis环境配置整合详解
idea spring+springmvc+mybatis环境配置整合详解 1.配置整合前所需准备的环境: 1.1:jdk1.8 1.2:idea2017.1.5 1.3:Maven 3.5.2 2. ...
- Spring+springmvc+Mybatis整合案例 annotation版(myeclipse)详细版
Spring+springmvc+Mybatis整合案例 Version:annotation版 文档结构图: 从底层开始做起: 01.配置web.xml文件 <?xml version=&qu ...
- 框架篇:Spring+SpringMVC+Mybatis整合开发
前言: 前面我已搭建过ssh框架(http://www.cnblogs.com/xrog/p/6359706.html),然而mybatis表示不服啊. Mybatis:"我抗议!" ...
- ssm之spring+springmvc+mybatis整合初探
1.基本目录如下 2.首先是向lib中加入相应的jar包 3.然后在web.xml中加入配置,使spring和springmvc配置文件起作用. <?xml version="1. ...
- Spring+SpringMVC+MyBatis整合基础篇(三)搭建步骤
作者:13GitHub:https://github.com/ZHENFENG13版权声明:本文为原创文章,未经允许不得转载. 框架介绍 Spring SpringMVC MyBatis easyUI ...
- Spring+SpringMVC+MyBatis整合(山东数漫江湖)
Spring+SpringMVC+MyBatis(SSM)在我们项目中是经常用到的,这篇文章主要讲解使用Intellij IDEA整合SSM,具体环境如下: 数据库:MySQL5.7 依赖管理:Mav ...
- Spring+SpringMVC+MyBatis整合进阶篇(四)RESTful实战(前端代码修改)
前言 前文<RESTful API实战笔记(接口设计及Java后端实现)>中介绍了RESTful中后端开发的实现,主要是接口地址修改和返回数据的格式及规范的修改,本文则简单介绍一下,RES ...
随机推荐
- ROS中.launch文件的remap标签详解
https://www.cnblogs.com/LiuQiang921202/p/7679943.html
- node 下查看安装插件的最新版本号的方法
例如查看extract-text-webpack-plugin的最新版本号 (不一定时本地安装的插件的版本号) npm view extract-text-webpack-plugin version ...
- C和C指针小记(三)-整型,char,枚举
1.C语言基本数据类型-整型 仅有4中机泵数据类型:整型,浮点型,指针,聚合类型(数组和结构) 整型家族:字符,短整型,整型,长整型.(都分有符号[singed]和无符号[unsinged]) 短整型 ...
- rtd1296 mtd 设备驱动分析
mtd 分区一般采用3种方式实现 1.内核写死 mtd_partition 2.u-boot 传参 为了使kernel能够解析mtdparts信息,我们需要将内核中的Device Drivers - ...
- 树和二叉树->线索二叉树
文字描述 从二叉树的遍历可知,遍历二叉树的输出结果可看成一个线性队列,使得每个结点(除第一个和最后一个外)在这个线形队列中有且仅有一个前驱和一个后继.但是当采用二叉链表作为二叉树的存储结构时,只能得到 ...
- adg的数据传输应用三大模式转换
1.最大可用性模式(Maximum Availability) 1)该模式提供了仅次于"最大保护模式"的数据保护能力: 2)要求至少一个物理备库收到重做日志后,主库的事务才能够提交 ...
- 《Redis 数据操作》
一:字符串类型(string) - 应用场景 - 用于常规计数,常规的 key-value 存储. - 常用操作 常用操作 设置一个值为(字符串类型) SET key value 设置一个值并设置过 ...
- php 数值类型
一.整形 1. 常见的整形 echo 1234; // 十进制数 echo -123; // 负数 echo 0123; // 八进制数 (等于十进制 83) echo 0x1A; // 十六进制数 ...
- JDBC的简单封装
import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import ...
- 1、 LwIP协议栈规范翻译——简介
1.简介 在过去几年中,计算机和计算机支持设备接之间的互联到无线网络日趋增加.计算机已经越来越无缝的集成在了日常的设备且价格也在下降.同时,无线网络技术例如蓝牙[HNI+98]和IEEE802.11b ...