spring整合springmvc和mybatis
1.spring
1.1 jar包
1.2 spring基本配置,包扫描注解
<!-- 自动扫描 -->
<context:component-scan base-package="com.getword">
<!-- 扫描时跳过 @Controller 注解的JAVA类(控制器) -->
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan>
2 mybatis
2.1 jar包
额外的jar包:
cjlib字节码增强、fileupload、io增强等
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:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:mybatis="http://mybatis.org/schema/mybatis-spring" xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://mybatis.org/schema/mybatis-spring http://mybatis.org/schema/mybatis-spring.xsd"> <!-- mybatis:scan会扫描com.getword.dao包里的所有接口当作Spring的bean配置,之后可以进行依赖注入-->
<mybatis:scan base-package="com.getword.dao"/> <!-- 扫描com.getword包下面的java文件,有Spring的相关注解的类,则把这些类注册为Spring的bean -->
<!--<context:component-scan base-package="com.getword"/>--> <!-- 自动扫描 -->
<context:component-scan base-package="com.getword">
<!-- 扫描时跳过 @Controller 注解的JAVA类(控制器) -->
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan> <!-- 使用PropertyOverrideConfigurer后处理器加载数据源参数 -->
<context:property-override location="classpath:db.properties"/> <!-- 配置c3p0数据源 -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"/> <!-- 2.配置sqlsessionfactory -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<!--注入数据源-->
<property name="dataSource" ref="dataSource"></property>
<!-- 设置mybatis配置文件路径 -->
<!--<property name="configLocation" value="classpath:mybatis-config.xml"></property>-->
</bean> <!-- JDBC事务管理器 -->
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager"
p:dataSource-ref="dataSource"/> <!-- 启用支持annotation注解方式事务管理 -->
<tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true"/> <!---文件下载,处理器-->
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="defaultEncoding" value="UTF-8"/>
<!-- maxUploadSize设置-1 不限制文件大小 -->
<property name="maxUploadSize" value="-1"/>
</bean> </beans>
3 spring mvc
3.1 fastjson的使用
配置:
<!-- 设置配置方案 -->
<mvc:annotation-driven>
<!-- 设置不使用默认的消息转换器 -->
<mvc:message-converters register-defaults="false">
<!-- 配置Spring的转换器 -->
<bean class="org.springframework.http.converter.StringHttpMessageConverter"/>
<bean class="org.springframework.http.converter.xml.XmlAwareFormHttpMessageConverter"/>
<bean class="org.springframework.http.converter.ByteArrayHttpMessageConverter"/>
<bean class="org.springframework.http.converter.BufferedImageHttpMessageConverter"/>
<!-- 配置fastjson中实现HttpMessageConverter接口的转换器 -->
<bean id="fastJsonHttpMessageConverter"
class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter">
<!-- 加入支持的媒体类型:返回contentType -->
<property name="supportedMediaTypes">
<list>
<!-- 这里顺序不能反,一定先写text/html,不然ie下会出现下载提示 -->
<value>text/html;charset=UTF-8</value>
<value>application/json;charset=UTF-8</value>
</list>
</property>
</bean>
</mvc:message-converters>
</mvc:annotation-driven>
对于返回String类型的数据乱码:
<!-- 配置Spring的转换器, 字符编码 -->
<bean class="org.springframework.http.converter.StringHttpMessageConverter">
<constructor-arg value="UTF-8" index="0"/>
<property name="supportedMediaTypes">
<list>
<value>text/plain;charset=UTF-8</value>
</list>
</property>
</bean>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<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>
<!--前端控制器-->
<servlet>
<servlet-name>sprintmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:springmvc-config.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>sprintmvc</servlet-name>
<url-pattern>*.do</url-pattern>
</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>
end
spring整合springmvc和mybatis的更多相关文章
- spring整合springMVC、mybatis、shiro
jar包: <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding& ...
- spring整合springMVC、mybatis、hibernate、mongodb框架
开发环境 eclipse Mars 4.5 JDK 1.7 框架 spring 4.0.5 mybatis 3.2.7 hibernate 4.3.6 mongodb 1.7 数据库 MySQL 5. ...
- spring、springmvc、mybatis整合笔记
这段时间上一个项目刚做完,下一个项目还没开始,趁这个时候来认真总结一下上个项目使用的ssm开发框架.由于,项目中关于使用ssm这部分的代码和配置是我们项目的整体架构师一个独立完成的,我们只负责业务部分 ...
- SSM框架整合(Spring、SpringMVC、Mybatis)
#毫无疑问我们肯定是使用Spring去整合SpringMVC和Mybatis,在整合过程中我们首先要让各自的模块实现,然后再去使用Spring整合:比如我先实现Mybatis框架的配置,然后再通过测试 ...
- SSM ( Spring 、 SpringMVC 和 Mybatis )配置详解
使用 SSM ( Spring . SpringMVC 和 Mybatis )已经有三个多月了,项目在技术上已经没有什么难点了,基于现有的技术就可以实现想要的功能,当然肯定有很多可以改进的地方.之前没 ...
- ssm(Spring、Springmvc、Mybatis)实战之淘淘商城-第一天
文章大纲 一.课程介绍二.淘淘商城基本介绍三.后台管理系统工程结构与搭建四.svn代码管理五.项目源码与资料下载六.参考文章 一.课程介绍 1. 课程大纲 一共14天课程(1)第一天:电商行业的背 ...
- ssm(Spring、Springmvc、Mybatis)实战之淘淘商城-第十四天(非原创)
文章大纲 一.淘淘商城总体架构介绍二.淘淘商城重要技术点总结三.项目常见面试题四.项目学习(all)资源下载五.参考文章 一.淘淘商城总体架构介绍 1. 功能架构 2. 技术选型 (1)Sprin ...
- 基于Spring、SpringMVC、MyBatis、Druid、Shrio构建web系统
源码下载地址:https://github.com/shuaijunlan/Autumn-Framework 在线Demo:http://autumn.shuaijunlan.cn 项目介绍 Autu ...
- spring整合springmvc和hibernate
上篇文章使用maven搭建了web环境,这篇来记录下如何使用spring整合springmvc和hibernate,亦即spring+springmvc+hibernate框架整合. 第一步:首先配置 ...
随机推荐
- 牛客网提高组模拟赛第五场 T1同余方程(异或)(位运算)
区间不好做,但是我们可以转化成前缀来做.转化为前缀之后之后就是二维前缀和. 但是我还是不怎么会做.所以只能去看吉老师的题解 (确定写的那么简单真的是题解???). 我们要求模一个数余0,就等于找它的倍 ...
- [HNOI2003]消防局的设立(树上距离为k的最小覆盖问题)
题目的大概意思现在有一棵树,在树上找半径小于等于2的最小覆盖点的最小个数. 题目链接 讲一讲此类题的贪心策略: 就是每次寻找最低没有被覆盖的点,显然对于覆盖它的所有点中,在他的祖先处设立一个点最优.所 ...
- 如果使用安卓4.4的SD卡?
安卓4.4默认情况下,后安装的程序无权写入数据到SD卡中,那么是否我们就不能用了?看了很多文章,都说要Root,随后修改配置文件.我觉得这不是很好的方法,Root之后的安卓会有很大风险,这不是最好的办 ...
- LAYABOX 开发遇到的问题记录
1. 如若在MAC下用LAYA开发H5游戏, 调试的时候会发现像素点过小(mac 5k屏),直接用下面按比例填充就好了 //保持原始高宽比的情况下,将舞台铺满屏幕,超出比例的部分会有黑边 ...
- Mac 上安装python3
1.安装包管理器 去包管理器官网按照提示安装包管理器 Homebrew 2.安装python3 安装完Homebrew ,输入指令安装python3 brew install python3 3.安装 ...
- bzoj 4283 魔法少女伊莉雅
题目大意 给定一个 $n$ 个点 $m$ 条边的带正权无向图.要求找一条路径满足: 它是一条简单路径 它是一条严格次短路 对于任何一条可能存在于最短路上的边,不能包含它的反向边. 不存在这条路径输出 ...
- [ActionSprit 3.0] FMS客户端与服务器端交互(传参)
客户端as: import flash.net.NetConnection; import flash.events.NetStatusEvent; var nc:NetConnection = ne ...
- 部署LNMP架构及其应用
部署企业LNMP架构 (一)首先安装nginx服务,具体请见另一篇关于nginx的博文. (二)安装MySQL数据库 .安装前准备 [root@localhost ~]# rpm -e mysql-s ...
- PyQt5(4)——菜单栏(使用外部exe)
图像化建立菜单栏: ① 双击输入名称 就可以喽 如何添加工具栏呢: 新建一个快捷工具,拖到快捷栏,出现红色的小竖线. 至此 就完成了菜单栏和快捷方式的建立. 补充: python 如何调用外部的e ...
- scrapy连接MySQL
Scrapy中连接MySQL所需要做的工作如下: 1.settings中需要设置的部分 # 启动管道组件 ITEM_PIPELINES = { 'QianChengWuYu.mongoDBPiplel ...