No.1 首先将web工程结构建好
1.1.1 开发环境介绍
在这里我是采用的是MySQL数据库
编译器版本采用的是jdk使用的是1.8
开发工具是使用的是eclipse Mars版本
web容器采用的是tomcat 版本是7.0版本
在这里我将我自己写好的Demo工程目录结构截图展示出来方便大家新建项目
这张图图片清晰地将我的工程清晰地展示出来,先简单介绍下吧 ,项目主包是以com.cntv开始的 。在之下又分为好几个子包,分别是mapper、controller、service、dao、mapper、logs、config、base、entity、test包,其中controller包是负责接收前台请求执行部分业务逻辑的action,熟悉struts框架的应该知道Action哈 在这里我就不详细说了。mapper包主要是负责mybatis框架实体映射,config包是主要存储项目配置文件。 其他的包就不一一介绍了,都是些常规的包。
NO.2 准备好相应的jar包
这里我是采用Spring是.2.0版本 mybatis是3.3.0版本的
图中框选的jar包是一些依赖性jar包 不要以为这就是完整的jar包 还有呢....
到此为止 jar包已准备完毕 现在就来开始准备框架的相关的配置了 首先是spring+mybatis关联的配置
NO.3 配置框架相关功能的配置文件
在src目录中config文件夹中新建spring-mybatis.xml文件 ,通过这个文件集成并关联Spring+mybatis框架
<?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.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
destroy-method="close">
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
紧接着在src下config包下新建jdbc.properties文化 把数据库的配置放在这个配置文件里面
driver=com.mysql.jdbc.Driver
url=jdbc:mysql://125.221.225.113:3306/db_zsl
username=demao
password=demao
#定义初始连接数
initialSize=0
#定义最大连接数
maxActive=20
#定义最大空闲
maxIdle=20
#定义最小空闲
minIdle=1
#定义最长等待时间
maxWait=60000
说明:第一