♦创建queen-parent工程

点击File ->New->Module…,创建maven项目

maven聚合项目部署服务器 idea创建maven聚合工程_maven聚合项目部署服务器

♦点击Next,填写组织名称和项目名称,以及版本号(GAV)


maven聚合项目部署服务器 idea创建maven聚合工程_spring_02


♦点击Next


maven聚合项目部署服务器 idea创建maven聚合工程_spring_03


♦点击Next,父工程最后一步,给Module取名及选择工作目录


maven聚合项目部署服务器 idea创建maven聚合工程_spring_04


♦点击Finish,完成


♦Pom文件完整如下


<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<groupId>com.queen.parent</groupId>
	<artifactId>queen-parent</artifactId>
	<version>1.0-SNAPSHOT</version>
	<packaging>pom</packaging>

	<!-- 集中定义依赖版本号 -->
	<properties>
		<junit.version>4.10</junit.version>
		<spring.version>4.1.3.RELEASE</spring.version>
		<mybatis.version>3.2.8</mybatis.version>
		<mybatis.spring.version>1.2.2</mybatis.spring.version>
		<mybatis.paginator.version>1.2.15</mybatis.paginator.version>
		<mysql.version>5.1.32</mysql.version>
		<slf4j.version>1.6.4</slf4j.version>
		<jackson.version>2.4.2</jackson.version>
		<druid.version>1.0.9</druid.version>
		<httpclient.version>4.3.5</httpclient.version>
		<jstl.version>1.2</jstl.version>
		<servlet-api.version>2.5</servlet-api.version>
		<jsp-api.version>2.0</jsp-api.version>
		<joda-time.version>2.5</joda-time.version>
		<commons-lang3.version>3.3.2</commons-lang3.version>
		<commons-io.version>1.3.2</commons-io.version>
	</properties>

	<dependencyManagement>
		<dependencies>
			<!-- 单元测试 -->
			<dependency>
				<groupId>junit</groupId>
				<artifactId>junit</artifactId>
				<version>${junit.version}</version>
				<scope>test</scope>
			</dependency>

			<!-- Spring -->
			<dependency>
				<groupId>org.springframework</groupId>
				<artifactId>spring-context</artifactId>
				<version>${spring.version}</version>
			</dependency>
			<dependency>
				<groupId>org.springframework</groupId>
				<artifactId>spring-beans</artifactId>
				<version>${spring.version}</version>
			</dependency>
			<dependency>
				<groupId>org.springframework</groupId>
				<artifactId>spring-webmvc</artifactId>
				<version>${spring.version}</version>
			</dependency>
			<dependency>
				<groupId>org.springframework</groupId>
				<artifactId>spring-jdbc</artifactId>
				<version>${spring.version}</version>
			</dependency>
			<dependency>
				<groupId>org.springframework</groupId>
				<artifactId>spring-aspects</artifactId>
				<version>${spring.version}</version>
			</dependency>

			<!-- Mybatis -->
			<dependency>
				<groupId>org.mybatis</groupId>
				<artifactId>mybatis</artifactId>
				<version>${mybatis.version}</version>
			</dependency>
			<dependency>
				<groupId>org.mybatis</groupId>
				<artifactId>mybatis-spring</artifactId>
				<version>${mybatis.spring.version}</version>
			</dependency>
			<!-- 分页助手 -->
			<dependency>
				<groupId>com.github.pagehelper</groupId>
				<artifactId>pagehelper</artifactId>
				<version>3.7.5</version>
			</dependency>
			<dependency>
				<groupId>com.github.jsqlparser</groupId>
				<artifactId>jsqlparser</artifactId>
				<version>0.9.1</version>
			</dependency>
			<!-- 通用Mapper -->
			<dependency>
				<groupId>com.github.abel533</groupId>
				<artifactId>mapper</artifactId>
				<version>2.3.4</version>
			</dependency>

			<!-- MySql -->
			<dependency>
				<groupId>mysql</groupId>
				<artifactId>mysql-connector-java</artifactId>
				<version>${mysql.version}</version>
			</dependency>

			<dependency>
				<groupId>org.slf4j</groupId>
				<artifactId>slf4j-log4j12</artifactId>
				<version>${slf4j.version}</version>
			</dependency>

			<!-- Jackson Json处理工具包 -->
			<dependency>
				<groupId>com.fasterxml.jackson.core</groupId>
				<artifactId>jackson-databind</artifactId>
				<version>${jackson.version}</version>
			</dependency>

			<!-- 连接池 -->
			<dependency>
				<groupId>com.jolbox</groupId>
				<artifactId>bonecp-spring</artifactId>
				<version>0.8.0.RELEASE</version>
			</dependency>

			<!-- httpclient -->
			<dependency>
				<groupId>org.apache.httpcomponents</groupId>
				<artifactId>httpclient</artifactId>
				<version>${httpclient.version}</version>
			</dependency>

			<!-- JSP相关 -->
			<dependency>
				<groupId>jstl</groupId>
				<artifactId>jstl</artifactId>
				<version>${jstl.version}</version>
			</dependency>
			<dependency>
				<groupId>javax.servlet</groupId>
				<artifactId>servlet-api</artifactId>
				<version>${servlet-api.version}</version>
				<scope>provided</scope>
			</dependency>
			<dependency>
				<groupId>javax.servlet</groupId>
				<artifactId>jsp-api</artifactId>
				<version>${jsp-api.version}</version>
				<scope>provided</scope>
			</dependency>

			<!-- 时间操作组件 -->
			<dependency>
				<groupId>joda-time</groupId>
				<artifactId>joda-time</artifactId>
				<version>${joda-time.version}</version>
			</dependency>

			<!-- Apache工具组件 -->
			<dependency>
				<groupId>org.apache.commons</groupId>
				<artifactId>commons-lang3</artifactId>
				<version>${commons-lang3.version}</version>
			</dependency>
			<dependency>
				<groupId>org.apache.commons</groupId>
				<artifactId>commons-io</artifactId>
				<version>${commons-io.version}</version>
			</dependency>

		</dependencies>
	</dependencyManagement>

	<build>
		<finalName>${project.artifactId}</finalName>
		<plugins>
			<!-- 资源文件拷贝插件 -->
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-resources-plugin</artifactId>
				<version>2.7</version>
				<configuration>
					<encoding>UTF-8</encoding>
				</configuration>
			</plugin>
			<!-- java编译插件 -->
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-compiler-plugin</artifactId>
				<version>3.2</version>
				<configuration>
					<source>1.7</source>
					<target>1.7</target>
					<encoding>UTF-8</encoding>
				</configuration>
			</plugin>
		</plugins>
		<pluginManagement>
			<plugins>
				<!-- 配置Tomcat插件 -->
				<plugin>
					<groupId>org.apache.tomcat.maven</groupId>
					<artifactId>tomcat7-maven-plugin</artifactId>
					<version>2.2</version>
				</plugin>
			</plugins>
		</pluginManagement>
	</build>
</project>




注意:项目的打包方式为pom

♦创建公用工程queen-common


点击File->New->Module…,进入以下界面,请按照下图红色框框进行选中

maven聚合项目部署服务器 idea创建maven聚合工程_maven聚合项目部署服务器_05



♦点击Next



maven聚合项目部署服务器 idea创建maven聚合工程_maven_06




♦点击Next



maven聚合项目部署服务器 idea创建maven聚合工程_maven_07




♦点击Next



maven聚合项目部署服务器 idea创建maven聚合工程_apache_08







点击Finish,创建成功
♦Pom文件如下:


<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<groupId>com.queen.common</groupId>
	<artifactId>queen-common</artifactId>
	<parent>
		<groupId>com.queen.parent</groupId>
		<artifactId>queen-parent</artifactId>
		<version>1.0-SNAPSHOT</version>
	</parent>
</project>




注意:项目的打包方式为jar和父项目有所不同

♦创建queen-manage

跟前面创建queen-parent步骤类似,就不再赘述了,注意:下面打包方式为pom




maven聚合项目部署服务器 idea创建maven聚合工程_spring_09




maven聚合项目部署服务器 idea创建maven聚合工程_maven聚合项目部署服务器_10


♦点击Finish,创建成功

pom文件如下



<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.queen.manage</groupId> <artifactId>queen-manage</artifactId> <packaging>pom</packaging> <parent> <groupId>com.queen.parent</groupId> <artifactId>queen-parent</artifactId> <version>1.0-SNAPSHOT</version> </parent></project>

♦接下来我们创建工程queen-manage的子模块工程queen-manage-pojo


♦点击Next
♦点击Next
♦点击Next
♦点击Finish完成

紧接着我们依次创建queen-manage-mapper,queen-manage-service,queen-manage-controller工程,步骤跟queen-manage-pojo一样。

注意:在我们创建queen-manage-controller时,打包方式要选择war。

♦最终我们新建的所有工程如下:
♦现在我们要整理一下子工程之间的依赖关系

queen-manage-controller-依赖-queen-manage-service-依赖-queen-manage-mapper-依赖-queen-manage-pojo

上面可知,我们的依赖关系如此。

那我们修改一下pom文件

在queen-manage-mapper的pom文件中加入queen-manage-pojo的坐标

<dependency>
	<groupId>com.queen.manage</groupId>
	<artifactId>queen-manage-pojo</artifactId>
	<version>0.0.1-SNAPSHOT</version>
</dependency>

在queen-manage-service的pom文件中加入queen-manage-mapper的坐标

<dependency>
	<groupId>com.queen.manage</groupId>
	<artifactId>queen-manage-mapper</artifactId>
	<version>0.0.1-SNAPSHOT</version>
</dependency>

在queen-manage-controller的pom文件中加入queen-manage-service的坐标

<dependency>
	<groupId>com.queen.manage</groupId>
	<artifactId>queen-manage-service</artifactId>
	<version>0.0.1-SNAPSHOT</version>
</dependency>
♦各个工程中导入依赖

在queen-manage-controller工程的pom文件完整依赖:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>com.queen.manage</groupId>
    <artifactId>queen-manage</artifactId>
    <version>0.0.1-SNAPSHOT</version>
  </parent>
  <artifactId>queen-manage-controller</artifactId>
  <packaging>war</packaging>
  <dependencies>
		<dependency>
			<groupId>com.queen.manage</groupId>
			<artifactId>queen-manage-service</artifactId>
			<version>1.0.0-SNAPSHOT</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-jdbc</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-aspects</artifactId>
		</dependency>
		<dependency>
			<groupId>org.mybatis</groupId>
			<artifactId>mybatis-spring</artifactId>
		</dependency>
		<!-- MySql -->
		<dependency>
			<groupId>mysql</groupId>
			<artifactId>mysql-connector-java</artifactId>
		</dependency>
		<!-- Jackson Json处理工具包 -->
		<dependency>
			<groupId>com.fasterxml.jackson.core</groupId>
			<artifactId>jackson-databind</artifactId>
		</dependency>
		<!-- 连接池 -->
		<dependency>
			<groupId>com.jolbox</groupId>
			<artifactId>bonecp-spring</artifactId>
		</dependency>
		<!-- JSP相关 -->
		<dependency>
			<groupId>jstl</groupId>
			<artifactId>jstl</artifactId>
		</dependency>
		<dependency>
			<groupId>javax.servlet</groupId>
			<artifactId>servlet-api</artifactId>
			<scope>provided</scope>
		</dependency>
		<dependency>
			<groupId>javax.servlet</groupId>
			<artifactId>jsp-api</artifactId>
			<scope>provided</scope>
		</dependency>
		<dependency>
			<groupId>commons-fileupload</groupId>
			<artifactId>commons-fileupload</artifactId>
			<version>1.3.1</version>
		</dependency>
		<!-- 时间操作组件 -->
		<dependency>
			<groupId>joda-time</groupId>
			<artifactId>joda-time</artifactId>
		</dependency>
	</dependencies>
</project>

在queen-manage-service工程的pom文件完整依赖

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>com.queen.manage</groupId>
    <artifactId>queen-manage</artifactId>
    <version>1.0.0-SNAPSHOT</version>
  </parent>
  <artifactId>queen-manage-service</artifactId>
  <dependencies>
		<dependency>
			<groupId>com.queen.manage</groupId>
			<artifactId>queen-manage-mapper</artifactId>
			<version>0.0.1-SNAPSHOT</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-webmvc</artifactId>
		</dependency>
		<!-- 分页助手 -->
		<dependency>
			<groupId>com.github.pagehelper</groupId>
			<artifactId>pagehelper</artifactId>
		</dependency>
		<dependency>
			<groupId>com.github.jsqlparser</groupId>
			<artifactId>jsqlparser</artifactId>
		</dependency>
	</dependencies>
</project>

在queen-manage-mapper工程的pom文件完整依赖:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>com.queen.manage</groupId>
    <artifactId>queen-manage</artifactId>
    <version>0.0.1-SNAPSHOT</version>
  </parent>
  <artifactId>queen-manage-mapper</artifactId>
  <dependencies>
		<dependency>
			<groupId>com.queen.manage</groupId>
			<artifactId>queen-manage-pojo</artifactId>
			<version>0.0.1-SNAPSHOT</version>
		</dependency>
		<!-- Mybatis -->
		<dependency>
			<groupId>org.mybatis</groupId>
			<artifactId>mybatis</artifactId>
		</dependency>
		<!-- 通用Mapper -->
		<dependency>
			<groupId>com.github.abel533</groupId>
			<artifactId>mapper</artifactId>
			<exclusions>
				<exclusion>
					<artifactId>persistence-api</artifactId>
					<groupId>javax.persistence</groupId>
				</exclusion>
			</exclusions>
		</dependency>
	</dependencies>
</project>

在queen-manage-pojo工程的pom文件完整依赖:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>com.queen.manage</groupId>
    <artifactId>queen-manage</artifactId>
    <version>0.0.1-SNAPSHOT</version>
  </parent>
  <artifactId>queen-manage-pojo</artifactId>
  <dependencies>
		<dependency>
			<groupId>javax.persistence</groupId>
			<artifactId>persistence-api</artifactId>
			<version>1.0</version>
		</dependency>
	</dependencies>
</project>

在queen-manage工程的pom文件完整依赖:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<parent>
		<groupId>com.queen.parent</groupId>
		<artifactId>queen-parent</artifactId>
		<version>0.0.1-SNAPSHOT</version>
	</parent>
	<groupId>com.queen.manage</groupId>
	<artifactId>queen-manage</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<packaging>pom</packaging>
	<modules>
		<module>queen-manage-pojo</module>
		<module>queen-manage-mapper</module>
		<module>queen-manage-service</module>
		<module>queen-manage-web</module>
	</modules>
	<dependencies>
		<dependency>
			<groupId>com.queen.common</groupId>
			<artifactId>queen-common</artifactId>
			<version>0.0.1-SNAPSHOT</version>
		</dependency>
		<!-- 单元测试 -->
		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<scope>test</scope>
		</dependency>
		<dependency>
			<groupId>org.slf4j</groupId>
			<artifactId>slf4j-log4j12</artifactId>
		</dependency>
		<!-- Apache工具组件 -->
		<dependency>
			<groupId>org.apache.commons</groupId>
			<artifactId>commons-lang3</artifactId>
		</dependency>
		<dependency>
			<groupId>org.apache.commons</groupId>
			<artifactId>commons-io</artifactId>
		</dependency>
	</dependencies>

	<build>
		<plugins>
			<!-- 配置Tomcat插件 -->
			<plugin>
				<groupId>org.apache.tomcat.maven</groupId>
				<artifactId>tomcat7-maven-plugin</artifactId>
				<configuration>
					<port>8080</port>
					<path>/</path>
				</configuration>
			</plugin>
		</plugins>
	</build>
</project>
♦运行工程,这里我们使用Maven Tomcat Plugin运行web项目

点击主界面右上角

,进入以下界面

注意:运行之前,每个工程需要clean和install一下 ,否则启动不了


集成SSM

jdbc.properties

jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/queen?characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance
jdbc.username=root
jdbc.password=root

log4j.properties

log4j.rootLogger =ALL,logDailyFile,logRollingFile,logDB,systemOut

#\u6309DatePattern\u8F93\u51FA\u5230\u6587\u4EF6
log4j.appender.logDailyFile = org.apache.log4j.DailyRollingFileAppender 
log4j.appender.logDailyFile.layout = org.apache.log4j.PatternLayout 
log4j.appender.logDailyFile.layout.ConversionPattern = [%-5p][%-22d{yyyy/MM/dd HH:mm:ssS}][%l]%n%m%n 
log4j.appender.logDailyFile.Threshold = INFO 
log4j.appender.logDailyFile.ImmediateFlush = TRUE 
log4j.appender.logDailyFile.Append = TRUE 
log4j.appender.logDailyFile.File = ../queen-parent/log4j_queen 
log4j.appender.logDailyFile.DatePattern = '.'yyyy-MM-dd-HH-mm'.log' 
log4j.appender.logDailyFile.Encoding = UTF-8 

#\u8BBE\u5B9A\u6587\u4EF6\u5927\u5C0F\u8F93\u51FA\u5230\u6587\u4EF6
log4j.appender.logRollingFile = org.apache.log4j.RollingFileAppender 
log4j.appender.logRollingFile.layout = org.apache.log4j.PatternLayout 
log4j.appender.logRollingFile.layout.ConversionPattern = [%-5p][%-22d{yyyy/MM/dd HH:mm:ssS}][%l]%n%m%n 
log4j.appender.logRollingFile.Threshold = INFO 
log4j.appender.logRollingFile.ImmediateFlush = TRUE 
log4j.appender.logRollingFile.Append = TRUE 
log4j.appender.logRollingFile.File = ../queen-parent/log4j_queen.log 
log4j.appender.logRollingFile.MaxFileSize = 1MB 
log4j.appender.logRollingFile.MaxBackupIndex = 10 
log4j.appender.logRollingFile.Encoding = UTF-8 

log4j.appender.systemOut = org.apache.log4j.ConsoleAppender 
log4j.appender.systemOut.layout = org.apache.log4j.PatternLayout 
log4j.appender.systemOut.layout.ConversionPattern = [%-5p][%-22d{yyyy/MM/dd HH:mm:ssS}][%l]%n%m%n 
log4j.appender.systemOut.Threshold = DEBUG 
log4j.appender.systemOut.ImmediateFlush = TRUE 
log4j.logger.java.sql=DEBUG
log4j.logger.java.sql.Connection=DEBUG    
log4j.logger.java.sql.Statement=DEBUG    
log4j.logger.java.sql.PreparedStatement=DEBUG
log4j.appender.systemOut.Target = System.out

mybatis.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration
        PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-config.dtd">

<configuration>

    <settings>
        <!-- 延迟加载总开关 -->
        <setting name="lazyLoadingEnabled" value="true" />
        <!-- 设置按需加载 -->
        <setting name="aggressiveLazyLoading" value="false" />
        <!-- 配置二级缓存 -->
        <setting name="cacheEnabled" value="true" />
        <!--解决,查询返回结果含null没有对应字段值问题-->
        <setting name="callSettersOnNulls" value="true"/>
    </settings>

    <!-- 别名 -->
    <typeAliases>
        <package name="com.queen.manage.pojo.User" />
    </typeAliases>

    <plugins>
        <!-- com.github.pagehelper为PageHelper类所在包名 -->
        <plugin interceptor="com.github.pagehelper.PageHelper">
            <!-- 设置数据库类型 Oracle,Mysql,MariaDB,SQLite,Hsqldb,PostgreSQL六种数据库-->
            <property name="dialect" value="mysql"/>
        </plugin>
    </plugins></configuration>

spring-mybatis.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:mvc="http://www.springframework.org/schema/mvc"
       xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"
       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-4.1.xsd
      http://www.springframework.org/schema/mvc
      http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd
      http://www.springframework.org/schema/context
      http://www.springframework.org/schema/context/spring-context-4.1.xsd
      http://www.springframework.org/schema/aop
      http://www.springframework.org/schema/aop/spring-aop-4.1.xsd
      http://www.springframework.org/schema/tx
      http://www.springframework.org/schema/tx/spring-tx-4.1.xsd ">

    <context:property-placeholder location="classpath:jdbc.properties" />

    <context:annotation-config></context:annotation-config>

    <context:component-scan base-package="com.queen.manage.*">


    </context:component-scan>
    <mvc:annotation-driven></mvc:annotation-driven>

    <import resource="spring-druid.xml" />
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <!-- 引用上面已经配置好的数据库连接池 -->
        <property name="dataSource" ref="dataSource" />
        <!-- Mybatis的配置文件路径 -->
        <property name="configLocation" value="classpath:mybatis.xml" />
        <property name="mapperLocations" value="classpath*:sqlmap/*.xml"/>
    </bean>

    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="com.queen.manage.mapper"/>
        <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>
    </bean>



    <!-- 声明式事务管理 -->
    <bean id="transactionManager"
          class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource" />
    </bean>
    <tx:advice id="userTxAdvice" transaction-manager="transactionManager">
        <tx:attributes>
            <tx:method name="insert*" propagation="REQUIRED" read-only="false"
                       isolation="READ_COMMITTED" rollback-for="java.lang.Exception" />
            <tx:method name="save*" propagation="REQUIRED" read-only="false"
                       isolation="READ_COMMITTED" rollback-for="java.lang.Exception" />
            <tx:method name="add*" propagation="REQUIRED" read-only="false"
                       isolation="READ_COMMITTED" rollback-for="java.lang.Exception" />
            <tx:method name="update*" propagation="REQUIRED" read-only="false"
                       isolation="READ_COMMITTED" rollback-for="java.lang.Exception" />
            <tx:method name="delete*" propagation="REQUIRED" read-only="false"
                       isolation="READ_COMMITTED" rollback-for="java.lang.Exception" />
            <tx:method name="remove*" propagation="REQUIRED" read-only="false"
                       isolation="READ_COMMITTED" rollback-for="java.lang.Exception" />
        </tx:attributes>
    </tx:advice>

    <aop:config expose-proxy="true" proxy-target-class="true">
        <aop:pointcut id="pc" expression="execution(* com.queen.manage.service.*.*(..))" />
        <aop:advisor pointcut-ref="pc" advice-ref="userTxAdvice" />
    </aop:config>

    <tx:annotation-driven proxy-target-class="true"
                          transaction-manager="transactionManager" />

</beans>

spring-mvc.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:mvc="http://www.springframework.org/schema/mvc"
       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.1.xsd
      http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd">
    <context:annotation-config></context:annotation-config>
    <mvc:annotation-driven></mvc:annotation-driven>
    <!-- 注解Controller扫描器 -->
    <context:component-scan base-package="com.queen.manage.controller" />

    <!-- 静态资源访问 -->
    <mvc:resources location="/fonts/" mapping="/fonts/**" />
    <mvc:resources location="/css/" mapping="/css/**" />
    <mvc:resources location="/images/" mapping="/images/**" />
    <mvc:resources location="/js/" mapping="/js/**" />
    <mvc:resources mapping="/WEB-INF/**" location="/WEB-INF/" />


    <!-- 注解功能的默认配置,处理器和映射器 -->
    <bean id="handlerMapping"
          class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" />


    <!-- 转为json格式 -->
    <!-- 避免IE执行ajax时,返回json出现下载文件 -->
    <bean id="mappingJacksonHttpMessageConverter"
          class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
        <property name="supportedMediaTypes">
            <list>
                <value>text/html;charset=UTF-8</value>
            </list>
        </property>
    </bean>

    <!-- 启动SpringMVC的注解功能,完成请求和注解POJO的映射 -->
    <bean
            class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
        <property name="messageConverters">
            <list>
                <!-- json转换器 -->
                <ref bean="mappingJacksonHttpMessageConverter" />
            </list>
        </property>
    </bean>
    <!-- 前后缀配置 -->
    <bean id="viewResolver"
          class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/"></property>
        <property name="suffix" value=".jsp"></property>
    </bean>
</beans>

spring-druid.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"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
      http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
      http://www.springframework.org/schema/context
      http://www.springframework.org/schema/context/spring-context-4.1.xsd
       ">

    <!-- 数据源配置 -->


    <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init"
          destroy-method="close">
        <property name="driverClassName" value="${jdbc.driver}" />
        <property name="url" value="${jdbc.url}" />
        <property name="username" value="${jdbc.username}" />
        <property name="password" value="${jdbc.password}" />
        <!-- 配置初始化大小、最小、最大 -->
        <property name="initialSize" value="1" />
        <property name="minIdle" value="1" />
        <property name="maxActive" value="20" />

        <!-- 配置获取连接等待超时的时间 -->
        <property name="maxWait" value="60000" />

        <!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 -->
        <property name="timeBetweenEvictionRunsMillis" value="60000" />

        <!-- 配置一个连接在池中最小生存的时间,单位是毫秒 -->
        <property name="minEvictableIdleTimeMillis" value="300000" />

        <property name="validationQuery" value="SELECT 'x'" />
        <property name="testWhileIdle" value="true" />
        <property name="testOnBorrow" value="false" />
        <property name="testOnReturn" value="false" />

        <!-- 打开PSCache,并且指定每个连接上PSCache的大小 -->
        <property name="poolPreparedStatements" value="true" />
        <property name="maxPoolPreparedStatementPerConnectionSize"
                  value="20" />
        <!-- 配置监控统计拦截的filters,去掉后监控界面sql无法统计 -->
        <property name="filters" value="stat" />
    </bean>
</beans>

web.xml下

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
  <display-name>queen-manage</display-name>
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>

  <!-- Spring和mybatis的配置文件 -->
  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:spring-mybatis.xml</param-value>
  </context-param>
  <!-- 编码过滤器 -->
  <filter>
    <filter-name>encodingFilter</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>encodingFilter</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>
  <!-- Spring监听器 -->
  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
  <!-- 防止Spring内存溢出监听器 -->
  <listener>
    <listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>
  </listener>

  <!-- Spring MVC servlet -->
  <servlet>
    <servlet-name>SpringMVC</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>classpath:spring-mvc.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>SpringMVC</servlet-name>
    <!-- 此处可以可以配置成*.do,对应struts的后缀习惯 -->
    <url-pattern>/</url-pattern>
  </servlet-mapping>
  <welcome-file-list>
    <welcome-file>/index.jsp</welcome-file>
  </welcome-file-list>


  <filter>
    <filter-name>DruidWebStatFilter</filter-name>
    <filter-class>com.alibaba.druid.support.http.WebStatFilter</filter-class>
    <init-param>
      <param-name>exclusions</param-name>
      <param-value>*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*</param-value>
    </init-param>
  </filter>
  <filter-mapping>
    <filter-name>DruidWebStatFilter</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>
  <servlet>
    <servlet-name>DruidStatView</servlet-name>
    <servlet-class>com.alibaba.druid.support.http.StatViewServlet</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>DruidStatView</servlet-name>
    <url-pattern>/druid/*</url-pattern>
  </servlet-mapping>
</web-app>

在queen-manage-pojo模块中创建com.queen.manage.pojo.User 类

创建sqlmap包 创建UserMapper.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.queen.manage.mapper.UserMapper">

    <select id="queryUser" resultType="com.queen.manage.pojo.User">
        SELECT *
        FROM t_user
    </select>
    <select id="queryUserById" resultType="java.util.Map" parameterType="com.queen.manage.pojo.User">
        SELECT *
        FROM t_user
        WHERE
        id=#{id}
    </select>
</mapper>

在queen-manage-mapper模块创建com.queen.manage.mapper.UserMapper接口

package com.queen.manage.mapper;

import com.queen.manage.pojo.User;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * Description
 *
 * @author wangsong
 * @date 10:12 2018/1/18
 */
public interface UserMapper {
    /**
     *Description 查询用户
     *@Author wangsong
     *@Date 10:13 2018/1/18
     *@param
     *@return
     *@throws
    */
    List<User> queryUser()throws Exception;
    /**
     *Description 根据ID查用户
     *@Author wangsong
     *@Date 14:14 2018/1/18
     *@param
     *@return
     *@throws
    */
    Map<String,String> queryUserById(User user)throws Exception;
}

同理创建dao,service接口和实现类

在web模块 即controller模块创建com.queen.manage.controller.UserController

package com.queen.manage.controller;


import com.queen.common.BaseConstant;
import com.queen.common.ResultBean;
import com.queen.manage.pojo.User;
import com.queen.manage.service.UserService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * Description
 *
 * @author wangsong
 * @date 10:16 2018/1/18
 */
@Controller
@RequestMapping("/user")
public class UserController {
    private static Logger logger = Logger.getLogger("logDailyFile");
    @Autowired
    private UserService userService;

    @ResponseBody
    @RequestMapping(value = "/query",method = RequestMethod.POST)
    public ResultBean queryUser()throws Exception{
        ResultBean resultBean=new ResultBean();
        try {
            List<User> maps=userService.queryUser();
            resultBean.setCode(BaseConstant.SUCCESSCODE);
            resultBean.setMessage(BaseConstant.SUCCESSMESSAGE);
            resultBean.setData(maps);
        } catch (Exception e) {
            logger.info(e.getMessage());
            resultBean.setCode(BaseConstant.ERRORCODE);
            resultBean.setMessage(BaseConstant.ERRORMESSAGE);
        }
        return resultBean;
    }

    @ResponseBody
    @RequestMapping(value = "/queryUser",method = RequestMethod.POST)
    public ResultBean queryUserById(User user)throws Exception{
        ResultBean resultBean=new ResultBean();
        try {
         Map<String,String> maps=userService.queryUserById(user);
            resultBean.setCode(BaseConstant.SUCCESSCODE);
            resultBean.setMessage(BaseConstant.SUCCESSMESSAGE);
            resultBean.setData(maps);
        } catch (Exception e) {
            logger.info(e.getMessage());
            resultBean.setCode(BaseConstant.ERRORCODE);
            resultBean.setMessage(BaseConstant.ERRORMESSAGE);
        }
        return resultBean;
    }
}

简单功能完成