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 ...
随机推荐
- mysql索引及sql执行顺序
1, 红黑树 同一层级的黑树到根结点经历的黑树数目一样 最坏情况的时间复杂度 lg n 是二叉树b树 结点可以有多个孩子 b+树 父节点不存储数据聚集索引)的叶子节点会存储数据行,也就是说数据和索引是 ...
- 广播消费:允许一个 Group ID 所标识的所有 Consumer 都会各自消费某条消息一次。
什么是消息队列 RocketMQ?_消息队列 RocketMQ-阿里云 https://help.aliyun.com/document_detail/29532.html 2019-01-30 16 ...
- 2012年蓝桥杯省赛A组c++第3题(喝断片的海盗)
/* 有一群海盗(不多于20人),在船上比拼酒量.过程如下:打开一瓶酒, 所有在场的人平分喝下,有几个人倒下了.再打开一瓶酒平分,又有倒下的, 再次重复...... 直到开了第4瓶酒,坐着的已经所剩无 ...
- 关于swagger-ui 参数为中文的时候,后端乱码
项目中用swagger-ui来测试接口,但是发现,参数是中文的时候,后台接收的时候会出现乱码. 不得改用postman,就没事了, 立贴求助,希望有人可以说下这个怎么配置. 后面发现是后端的编码过滤器 ...
- 20165225《Java程序设计》第九周学习总结
20165225<Java程序设计>第九周学习总结 1.视频与课本中的学习: 第十三章学习总结 URL类 URL对象包含三部分信息:协议.地址和资源 创建URL对象两种方法: public ...
- Python库源码学习1:Flask之app.run
先列出app.run()实现的功能,我们以debug=True的情况下进行分析. 1. web服务器,处理http请求 2. 当代码修改后,重启服务器 那么app.run()是如何实现这两个功能的呢? ...
- 安装sqlserver2008中出现的问题小结
安装完sqlserver2008时报了几个错,但是好歹装上了,但是我想使用sa用户登录,给我出现了这么一个错 标题: 连接到服务器------------------------------ 无法连接 ...
- C# Asp.net使用FormData对象实现ajax提交表单及上传图片
1.html代码: <form id="postForm"> 文件名:<input type="text" name="filena ...
- [MySQL 5.6] information_schema.innodb_metrics
1. 概括 已关闭/打开的配置 use information_schema select count(*), status from innodb_metrics group by status; ...
- 20181223 python 使用Beautiful Soup
(这篇,没什么营养价值) 怎么说呢! 爬虫吧!把html页面进行解析得到有效数据,而beautiful soup 能快速格式化页面再进行方法对数进行提取,存入想要存入的DB中. from bs4 im ...