1.创建maven的web项目,创建如下的简单目录结构:
2.在pom文件中添加相关jar包依赖以及配置tomcat插件:
<build>
<plugins>
<!-- tomcat插件 -->
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<!-- 端口号 -->
<port>8082</port>
<!-- /表示访问路径 省略项目名 -->
<path>/</path>
<!-- 设置编码方式 -->
<uriEncoding>utf-8</uriEncoding>
</configuration>
</plugin>
</plugins>
</build>
3.在/com-sb-ssm/src/main/resources目录下创建如下文件:
使用mybatis的逆向工程生成dao层的接口文件、映射文件、pojo类、pojoexample类:
4.配置文件的设置:
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"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.3.xsd">
<!-- 关联数据属性文件,注意加上classpath -->
<context:property-placeholder location="classpath:db.properties"/>
<!-- 开启扫描 -->
<context:component-scan base-package="com.sb.service.impl"/>
<!-- 配置数据源 -->
<bean class="com.mchange.v2.c3p0.ComboPooledDataSource"
id="dataSource" >
<property name="driverClass" value="${driverName}"></property>
<property name="jdbcUrl" value="${url}"></property>
<property name="user" value="${names}"><