按照上次的博客:
基于SpringMVC+Spring+Hibernate+Maven+Bootstrap的简单Demo
这次把Hibernate转换成Mybatis 3.4.1 基本变化在于数据操作层。
下面贴出代码变动的地方(没有贴出的跟上面一条博客相同,项目运行效果也是一致的),以及此次学习Mybatis用的参考文档.有关Ioc可以参考Spring Ioc详细配置与使用,有关AOP可以参考SpringAOP详细配置与使用,有关Mybatis可以参考Mybatis的工作流程及其原理与解析
目录结构图 :
bean.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:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
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">
<!-- 打开Spring的Annotation支持 -->
<context:annotation-config />
<!-- 设定Spring 去哪些包中找Annotation -->
<context:component-scan base-package="com.ctc" />
<!-- 导入Src目录下的jdbc.properties文件 -->
<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}" />
</bean>
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="DataSource" />
<property name="configLocation" value="classpath:sqlMapConfig.xml"/>
</