Spring3 整合 Mybatis3(一)

2014-11-24 10:26:41 · 作者: · 浏览: 4

Spring3 整合 Mybatis3
这两天,项目需要使用spring+ibatis,于是去网上下载了,结果发现和之前我用的版本变化不小,整了两天才将功能实现,不敢怠慢,赶紧写份博客记录一下。

首先是依赖的库:

接着是web.xml的配置,这里,我使用的是Spring3 MVC

[html]
< xml version="1.0" encoding="UTF-8" >

Log


welcome.html




log4jConfigLocation
/WEB-INF/classes/log4j.properties



contextConfigLocation
classpath:applicationContext*.xml




org.springframework.web.context.ContextLoaderListener




encodingFilter
org.springframework.web.filter.CharacterEncodingFilter

encoding
utf8




encodingFilter
*.do






dispatchServlet
org.springframework.web.servlet.DispatcherServlet

contextConfigLocation
classpath:servlet-config.xml

1



dispatchServlet
*.do


然后是spring的servlet配置servlet-config.xml:
[html] view plaincopy
< xml version="1.0" encoding="UTF-8" >
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"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">














text/html;charset=UTF-8















然后是Spring的Bean的配置文件applicationContext.xml:

[html]
< xml version="1.0" encoding="UTF-8" >
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"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">










mysql.jdbc.Driver" />











classpath:com/log/bean/mapper/*.xml