开发环境:jdk1.8+tomcat8.0+mysql+maven 3.0
开发工具:intellij idea
项目框架:SpringMVC+Spring+Mybatis
说明:搭建的项目,亲测好使
搭建步骤:
1、打开idea,选择file -> new -> project,如下图所示
2、选择maven -> 选择SDK ->点击next, 如下图所示
3、填写GroupId -> 填写ArtifactId -> 填写Version(这里选择默认的)-> next,如下图所示
4、输入project name -> 选择工程存贮目录 -> finish,如下图所示,然后删除src整个目录,只保留.idea目录,pom.xml、.ini文件
注:
(1)、上面的步骤是创建一个父容器,用于管理jar包
(2)、本列将划分五个model,dao(用于操作数据库)、model(实体类)、service(业务逻辑)、web(视图&控制器)、utils(工具类)
5、创建dao,选中项目主名称,右击鼠标 -> 选择 new -> model 如下图所示
6、重复步骤2和3
7、修改模块名称,如下图所示 -> finish
7、创建service、model、utils,步骤和创建dao一样
8、创建web,重复步骤5,稍作修改,具体如下图所示,其他按照提示一步步操作即可
9、创建后的项目结构如下所示
10、配置pom文件,注工程的pom文件添加如下内容
<properties>
<!--<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>-->
<!--<maven.compiler.encoding>UTF-8</maven.compiler.encoding>-->
<mybatis.version>3.3.0</mybatis.version>
<mybatis-spring.version>1.2.3</mybatis-spring.version>
<mybatis-generator.version>1.3.5</mybatis-generator.version>
<freemarker.version>2.3.20</freemarker.version>
<commons-io.version>2.4</commons-io.version>
<druid.version>1.0.9</druid.version>
<!-- 使用 mybatis-generator 时,用6.0.3警告找不到主键,无法生成使用主键的方法,生成代码时暂时先用5.1.34 -->
<mysql.version>5.1.34</mysql.version>
<!--<mysql.version>6.0.3</mysql.version>-->
<spring-version>4.3.2.RELEASE</spring-version>
<log4j.version>1.2.17</log4j.version>
<slf4j-api.version>1.7.5</slf4j-api.version>
<slf4j-log4j12.version>1.7.5</slf4j-log4j12.version>
<jcl-over-slf4j.version>1.7.5</jcl-over-slf4j.version>
<junit.version>4.12</junit.version>
<spring-test.version>3.2.4.RELEASE</spring-test.version>
<servlet-api.version>3.0.1</servlet-api.version>
<guava.version>18.0</guava.version>
<unirest.version>1.4.9</unirest.version>
<fastjson.version>1.2.6</fastjson.version>
<jjwt.version>0.6.0</jjwt.version>
<xstream.version>1.4.9</xstream.version>
<swagger.version>2.5.0</swagger.version>
<http-request.version>6.0</http-request.version>
<jackson-databind.version>2.4.2</jackson-databind.version>
<joda-time.version>2.8.2</joda-time.version>
</properties>
<dependencyManagement>
<dependencies>
<!--DB-->
<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.alibaba</groupId>
<artifactId>druid</artifactId>
<version>${druid.version}</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql.version}</version>
</dependency>
<!--spring-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring-version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</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-context</artifactId>
<version>${spring-version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
<version>${spring-version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>${spring-version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>${spring-version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</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-web</artifactId>
<version>${spring-version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${spring-version}</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.8.9</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.8.9</version>
</dependency>
<!--tools-->
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava.version}</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>${fastjson.version}</version>
</dependency>
<dependency>
<groupId>com.mashape.unirest</groupId>
<artifactId>unirest-java</artifactId>
<version>${unirest.version}</version>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt</artifactId>
<version>${jjwt.version}</version>
</dependency>
<!--add by hanxiaoyu 2016.11.22 start-->
<dependency>
<groupId>com.github.kevinsawicki</groupId>
<artifactId>http-request</artifactId>
<version>${http-request.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson-databind.version}</version>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>${joda-time.version}</version>
</dependency>
<!--add by hanxiaoyu 2016.11.22 end-->
<!--log-->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>${log4j.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j-api.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>${slf4j-log4j12.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>${jcl-over-slf4j.version}</version>
</dependency>
<!--mybatis-generator-->
<dependency>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>${mybatis-generator.version}</version>
<exclusions>
<!-- 排掉此包,对jenkins自动部署有影响 -->
<exclusion>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-core</artifactId>
<version>${mybatis-generator.version}</version>
</dependency>
<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
<version>${freemarker.version}</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>${commons-io.version}</version>
</dependency>
<!--test-->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring-test.version}</version>
<!--<scope>test</scope>-->
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>${servlet-api.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>${swagger.version}</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>${swagger.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.thoughtworks.xstream/xstream -->
<dependency>
<groupId>com.thoughtworks.xstream</groupId>
<artifactId>xstream</artifactId>
<version>${xstream.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<finalName>${project.artifactId}</finalName>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-source-plugin</artifactId>
<version>2.2.1</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
<configuration>
<attach>true</attach>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<webResources>
<resource>
<directory>src/main/webapp</directory>
<filtering>false</filtering>
</resource>
</webResources>
<!--<resourceEncoding>utf-8</resourceEncoding>-->
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.5</version>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<!--<plugin>-->
<!--<artifactId>maven-surefire-plugin</artifactId>-->
<!--<configuration>-->
<!--<forkMode>always</forkMode>-->
<!--<argLine>${surefire.argLine}</argLine>-->
<!--<runOrder>alphabetical</runOrder>-->
<!--<includes>-->
<!--<include>**/*Test.*</include>-->
<!--</includes>-->
<!--</configuration>-->
<!--</plugin>-->
</plugins>
</build>
<profiles>
<profile>
<id>development</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<profiles.active>dev</profiles.active>
<mybatis.log>ERROR</mybatis.log>
<log.level>INFO</log.level>
<log.path>/tourism/soft/apache-tomcat-7.0.47/logs/tourism.log</log.path>
<log.latency.path>/tourism/soft/apache-tomcat-7.0.47/logs/latency.log</log.latency.path>
<!--<log.path>/Users/guolanrui/Downloads/ctsappbk.log</log.path>-->
</properties>
</profile>
<profile>
<id>test</id>
<properties>
<profiles.active>test</profiles.active>
<mybatis.log>ERROR</mybatis.log>
<log.level>INFO</log.level>
<log.path>/tourism/soft/apache-tomcat-7.0.47/logs/tourism.log</log.path>
<log.latency.path>/tourism/soft/apache-tomcat-7.0.47/logs/latency.log</log.latency.path>
</properties>
</profile>
<profile>
<id>production</id>
<properties>
<profiles.active>pro</profiles.active>
<mybatis.log>ERROR</mybatis.log>
<log.level>INFO</log.level>
<log.path>/usr/local/tomcat_eduction/logs/tourism.log</log.path>
<log.latency.path>/usr/local/tomcat_eduction/logs/latency.log</log.latency.path>
</properties>
</profile>
</profiles>
11、web层,pom文件添加如下内容
<dependencies>
<dependency>
<groupId>com.h52mm</groupId>
<artifactId>tourism-service</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>taglibs</groupId>
<artifactId>standard</artifactId>
<version>1.1.2</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt</artifactId>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
</dependency>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.2.2</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.2.4</version>
</dependency>
<dependency>
<groupId>commons-net</groupId>
<artifactId>commons-net</artifactId>
<version>3.3</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-core-asl</artifactId>
<version>1.9.13</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.9.13</version>
</dependency>
<dependency>
<groupId>net.coobird</groupId>
<artifactId>thumbnailator</artifactId>
<version>0.4.8</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.8.0</version>
</dependency>
<!--导入itext-->
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>kernel</artifactId>
<version>7.0.4</version>
</dependency>
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>io</artifactId>
<version>7.0.4</version>
</dependency>
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>layout</artifactId>
<version>7.0.4</version>
</dependency>
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>forms</artifactId>
<version>7.0.4</version>
</dependency>
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>pdfa</artifactId>
<version>7.0.4</version>
</dependency>
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>pdftest</artifactId>
<version>7.0.4</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.18</version>
</dependency>
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>itext-licensekey</artifactId>
<version>2.0.4</version>
</dependency>
</dependencies>
<build>
<finalName>tourism-web</finalName>
<plugins>
<!--<plugin>-->
<!--<groupId>org.mortbay.jetty</groupId>-->
<!--<artifactId>maven-jetty-plugin</artifactId>-->
<!--<version>6.1.7</version>-->
<!--<configuration>-->
<!--<connectors>-->
<!--<connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">-->
<!--<port>8888</port>-->
<!--<maxIdleTime>30000</maxIdleTime>-->
<!--</connector>-->
<!--</connectors>-->
<!--<webAppSourceDirectory>${project.build.directory}/${pom.artifactId}-${pom.version}-->
<!--</webAppSourceDirectory>-->
<!--<contextPath>/</contextPath>-->
<!--</configuration>-->
<!--</plugin>-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>utf8</encoding>
</configuration>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>itext</id>
<name>iText Repository - releases</name>
<url>https://repo.itextsupport.com/releases</url>
</repository>
</repositories>
12、service pom文件
<dependencies>
<dependency>
<groupId>com.h52mm</groupId>
<artifactId>tourism-model</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.h52mm</groupId>
<artifactId>tourism-dao</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.h52mm</groupId>
<artifactId>tourism-utils</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt</artifactId>
</dependency>
<dependency>
<groupId>com.mashape.unirest</groupId>
<artifactId>unirest-java</artifactId>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
</dependency>
<dependency>
<groupId>com.thoughtworks.xstream</groupId>
<artifactId>xstream</artifactId>
</dependency>
<dependency>
<groupId>dom4j</groupId>
<artifactId>dom4j</artifactId>
<version>1.6.1</version>
</dependency>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>2.1.0</version>
</dependency>
<!--shiro权限管理-->
<!--<dependency>-->
<!--<groupId>org.apache.shiro</groupId>-->
<!--<artifactId>shiro-core</artifactId>-->
<!--<version>1.3.1</version>-->
<!--</dependency>-->
<!--<!– https://mvnrepository.com/artifact/org.apache.shiro/shiro-web –>-->
<!--<dependency>-->
<!--<groupId>org.apache.shiro</groupId>-->
<!--<artifactId>shiro-web</artifactId>-->
<!--<version>1.3.1</version>-->
<!--</dependency>-->
<!--<!– https://mvnrepository.com/artifact/org.apache.shiro/shiro-spring –>-->
<!--<dependency>-->
<!--<groupId>org.apache.shiro</groupId>-->
<!--<artifactId>shiro-spring</artifactId>-->
<!--<version>1.3.1</version>-->
<!--</dependency>-->
<!--<dependency>-->
<!--<groupId>org.apache.shiro</groupId>-->
<!--<artifactId>shiro-ehcache</artifactId>-->
<!--<version>1.3.1</version>-->
<!--</dependency>-->
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache</artifactId>
<version>2.10.2.2.21</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-redis</artifactId>
<version>1.0.0.RELEASE</version>
</dependency>
<!--Redis-->
<!-- https://mvnrepository.com/artifact/commons-collections/commons-collections -->
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.2</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
</dependency>
<!--<dependency>-->
<!--<groupId>com.aliyun.java</groupId>-->
<!--<artifactId>aliyun-core</artifactId>-->
<!--<version>1.0</version>-->
<!--</dependency>-->
<!--<dependency>-->
<!--<groupId>com.aliyun.java</groupId>-->
<!--<artifactId>aliyun-dysmsapi</artifactId>-->
<!--<version>1.0.0-SNAPSHOT</version>们-->
<!--</dependency>-->
<!--支付接口-->
<!--<dependency>-->
<!--<groupId>com.github.wxpay</groupId>-->
<!--<artifactId>wxpay-sdk-0.0.3</artifactId>-->
<!--<version>0.0.3</version>-->
<!--</dependency>-->
<!--<dependency>-->
<!--<groupId>com.alipay</groupId>-->
<!--<artifactId>sdk-java</artifactId>-->
<!--<version>20170615110434</version>-->
<!--</dependency>-->
<!--<dependency>-->
<!--<groupId>com.alipay</groupId>-->
<!--<artifactId>sdk-java-source</artifactId>-->
<!--<version>20170615110434</version>-->
<!--</dependency>-->
<!--<dependency>-->
<!--<groupId>com.google.zxing</groupId>-->
<!--<artifactId>core</artifactId>-->
<!--<version>3.1.0</version>-->
<!--</dependency>-->
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.9</version>
</dependency>
<!--quartz任务调度框架-->
<dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz</artifactId>
<version>2.2.1</version>
</dependency>
<dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz-jobs</artifactId>
<version>2.2.1</version>
</dependency>
<dependency>
<groupId>org.jdom</groupId>
<artifactId>jdom</artifactId>
<version>1.1.3</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</dependency>
<dependency>
<groupId>commons-httpclient</groupId>
<artifactId>commons-httpclient</artifactId>
<version>3.1</version>
</dependency>
</dependencies>
13、dao pom
<dependencies>
<dependency>
<groupId>com.h52mm</groupId>
<artifactId>tourism-model</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
</dependency>
<!--mybatis-generator-->
<dependency>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
</dependency>
<dependency>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-core</artifactId>
</dependency>
<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
</dependency>
<!--log-->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
</dependency>
</dependencies>
14、model pom
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
15、utils pom
<dependencies>
<dependency>
<groupId>com.github.kevinsawicki</groupId>
<artifactId>http-request</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
</dependencies>
注释:各模块引入的jar包,按照自己需求配置
15、配置环境,按下图操作
注释,每个模块都需要这样配置
16、按住 alt+f12打开控制台。执行命令 mvn clean install(安装jar)
注释,如果提示mvn不是命令,请配置好Maven的开发环境(环境变量要正确)
17、配置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_3_0.xsd"
id="WebApp_ID" version="3.0">
<display-name>Archetype Created Web Application</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<!--<!–shiro–>-->
<!--你好哈哈哈哈或或不斤斤计较-->
<filter>
<filter-name>CharacterEncodingFilter</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>CharacterEncodingFilter</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>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring/applicationContext.xml</param-value>
</context-param>
<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/spring-mvc.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>SpringMVC</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<!--<filter>-->
<!--<filter-name>shiroFilter</filter-name>-->
<!--<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>-->
<!--</filter>-->
<!--<filter-mapping>-->
<!--<filter-name>shiroFilter</filter-name>-->
<!--<url-pattern>/*</url-pattern>-->
<!--</filter-mapping>-->
<session-config>
<cookie-config>
<name>CTSHO_JSESSIONID</name>
<max-age>31536000</max-age>
</cookie-config>
</session-config>
<error-page>
<error-code>500</error-code>
<location>/error_500</location>
</error-page>
<error-page>
<error-code>404</error-code>
<location>/error_404</location>
</error-page>
<error-page>
<error-code>400</error-code>
<location>/error_400</location>
</error-page>
</web-app>
18、配置spring,在web层里面的resources包下新建文件夹,名为spring
19、在spring下创建文件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:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd">
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="classpath:config-${profiles.active}.properties" />
</bean>
<mvc:annotation-driven/>
<context:annotation-config/>
<context:component-scan base-package="com.h52mm.tourism.service">
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller" />
</context:component-scan>
<context:component-scan base-package="com.h52mm.tourism.thin">
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller" />
</context:component-scan>
<import resource="spring-datasource.xml"/>
<!--<import resource="spring-shiro.xml"/>-->
<!--<import resource="spring-quartz.xml"/>-->
</beans>
20、配置springMVC,在spring文件夹下新建 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"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd">
<aop:aspectj-autoproxy proxy-target-class="true"/>
<!-- 开启包扫描 -->
<context:component-scan base-package="com.h52mm.tourism.web.*">
<context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Service"/>
</context:component-scan>
<mvc:annotation-driven>
<mvc:message-converters register-defaults="true">
<bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
<property name="prefixJson" value="false" />
<property name="supportedMediaTypes" >
<list>
<value>text/html;charset=UTF-8</value>
</list>
</property>
<property name="objectMapper">
<bean class="com.fasterxml.jackson.databind.ObjectMapper">
<!-- 处理responseBody 里面日期类型 -->
<property name="dateFormat">
<bean class="java.text.SimpleDateFormat">
<constructor-arg type="java.lang.String" value="yyyy-MM-dd" />
</bean>
</property>
<!-- 为null字段时不显示 -->
<property name="serializationInclusion">
<value type="com.fasterxml.jackson.annotation.JsonInclude.Include">NON_NULL</value>
</property>
</bean>
</property>
</bean>
</mvc:message-converters>
</mvc:annotation-driven>
<!-- 单独为webApplicationContext注入placeholder,以便Controller中注入变量 -->
<context:property-placeholder ignore-unresolvable="true" location="classpath:config-${profiles.active}.properties"/>
<!-- 拦截器 -->
<!--<mvc:interceptors>-->
<!--<mvc:interceptor>-->
<!--<mvc:mapping path="/user/**"/>-->
<!--<mvc:mapping path="/department/**"/>-->
<!--<mvc:mapping path="/employee/**"/>-->
<!--<mvc:mapping path="/address/**"/>-->
<!--<!–<mvc:mapping path="/weixin/**"/>–>-->
<!--<mvc:mapping path="/associator/**"/>-->
<!--<!–<mvc:mapping path="/datePrice/*"/>–>-->
<!--<mvc:exclude-mapping path="/user/login"/>-->
<!--<mvc:exclude-mapping path="/user/verifycode"/>-->
<!--<bean class="com.lswd.youpin.web.interceptor.UserLoginInterceptor"/>-->
<!--</mvc:interceptor>-->
<!--</mvc:interceptors>-->
<!--拦截器-->
<!--<mvc:interceptors>-->
<!--<mvc:interceptor>-->
<!--<mvc:mapping path="/tenant/**"/>-->
<!--<mvc:mapping path="/canteen/**"/>-->
<!--<bean class="com.lswd.youpin.web.interceptor.LswdRequestInterceptor"/>-->
<!--</mvc:interceptor>-->
<!--</mvc:interceptors>-->
<!--<mvc:resources mapping="/apidoc/**" location="/apidoc/"/>-->
<!--<mvc:resources mapping="/angular-1.5.8/**" location="/angular-1.5.8/"/>-->
<!--<mvc:resources mapping="/bootstrap/**" location="/bootstrap/"/>-->
<!--<mvc:resources mapping="/bootstrap-date/**" location="/bootstrap-date/"/>-->
<!--<mvc:resources mapping="/js/**" location="/js/"/>-->
<!--<mvc:resources mapping="/css/**" location="/css/"/>-->
<!--<mvc:resources mapping="/images/**" location="/images/"/>-->
<!--<mvc:resources mapping="/font-awesome-4.7.0/**" location="/font-awesome-4.7.0/"/>-->
<!--<mvc:resources mapping="/echarts/**" location="/echarts/"/>-->
<!--<mvc:resources mapping="/video/**" location="/video/"/>-->
<!--<mvc:resources mapping="/font/**" location="/font/"/>-->
<!--<mvc:resources mapping="/easyui/**" location="/easyui/"/>-->
<!--<mvc:resources mapping="/kindeditor/**" location="/kindeditor/"/>-->
<!--配置文件上传的信息-->
<bean id="multipartResolver" class="com.h52mm.tourism.web.upload.CustomMultipartResolver">
<property name="maxUploadSize" value="3000000000"/>
<property name="maxInMemorySize" value="4096"/>
<property name="defaultEncoding" value="UTF-8"></property>
</bean>
<!--跨域处理-->
<mvc:cors>
<mvc:mapping path="/**"
allowed-origins="*"
allowed-methods="GET,PUT,POST,DELETE"
allowed-headers="Content-Type,x-requested-with,token,type,canteenId"
exposed-headers="token" allow-credentials="false"
max-age="3600" />
</mvc:cors>
<!--视图解析器-->
<bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="prefix" value="/WEB-INF/jsp/"/>
<!--<property name="contentType" value="text/html"/>-->
<property name="suffix" value=".jsp"/>
<property name="viewClass" value="org.springframework.web.servlet.view.InternalResourceView"/>
</bean>
</beans>
20、配置数据库连接,在spring文件夹新建spring-datasource.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
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"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.2.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.2.xsd">
<!-- 数据库连接池 -->
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close">
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
<property name="filters" value="stat" />
<property name="maxActive" value="20" />
<property name="initialSize" value="1" />
<property name="maxWait" value="5000" />
<property name="minIdle" value="1" />
<property name="timeBetweenEvictionRunsMillis" value="60000" />
<property name="minEvictableIdleTimeMillis" value="300000" />
<property name="testWhileIdle" value="true" />
<property name="testOnBorrow" value="false" />
<property name="testOnReturn" value="false" />
<property name="poolPreparedStatements" value="true" />
<property name="maxOpenPreparedStatements" value="20" />
<!--<property name="connectionErrorRetryAttempts" value="5" />-->
</bean>
<!-- 让spring管理sqlsessionfactory 使用mybatis和spring整合包中的 -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="mapperLocations" value="classpath:com.h52mm.tourism.mapper/*.xml"></property>
<!-- 数据库连接池 -->
<property name="dataSource" ref="dataSource" />
<!-- 加载mybatis的全局配置文 -->
<property name="configLocation" value="classpath:config/SqlMapConfig.xml" />
</bean>
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.h52mm.tourism.dao" />
</bean>
<!--<bean id="transactionManager"-->
<!--class="org.springframework.jdbc.datasource.DataSourceTransactionManager">-->
<!--<property name="dataSource" ref="dataSource" />-->
<!--</bean>-->
</beans>
21、在resources新建config-dev.properties
#数据库连接参数
jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://120.25.57.31:3306/student?useUnicode=true&characterEncoding=UTF-8
jdbc.username=root
jdbc.password=admin123456
#校验身份证号正则表达式
idNumber.regex=^[1-9][0-9]{5}(19[0-9]{2}|200[0-9]|2010)(0[1-9]|1[0-2])(0[1-9]|[12][0-9]|3[01])[0-9]{3}[0-9xX]$
22、在resources新建config文件夹,在config文件夹下新建SqlMapConfig.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="mapUnderscoreToCamelCase" value="true" />
<setting name="logImpl" value="LOG4J" />
</settings>
<!--<settings>
<setting name="cacheEnabled" value="true" />
<setting name="logImpl" value="STDOUT_LOGGING" />
</settings>
<typeAliases>
<!– 指定实体类 别名扫描包,mapper.xml文件中只需要写上实体类名即可,不区分大小写 –>
<package name="com.lswd.youpin.model.lsyp.*"/>
</typeAliases>-->
</configuration>
23、在resources新建log4j.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<appender name="file" class="org.apache.log4j.DailyRollingFileAppender">
<param name="Encoding" value="UTF-8" />
<param name="File" value="${log.path}" />
<param name="Append" value="false" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d [%t] %-5p: %l - %m%n" />
</layout>
</appender>
<appender name="latency" class="org.apache.log4j.DailyRollingFileAppender">
<param name="Encoding" value="UTF-8" />
<param name="File" value="${log.latency.path}" />
<param name="Append" value="false" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d [%t] %-5p: %l - %m%n" />
</layout>
</appender>
<appender name="console" class="org.apache.log4j.ConsoleAppender">
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d [%t] %-5p: %l - %m%n" />
</layout>
</appender>
<logger name="latencyLog" additivity="false">
<level value="${log.level}" />
<appender-ref ref="latency"/>
</logger>
<logger name="com.hkcts.ctsapp" additivity="false">
<level value="${log.level}" />
<appender-ref ref="console" />
<appender-ref ref="file" />
</logger>
<logger name="org.springframework" additivity="false">
<level value="${log.level}" />
<appender-ref ref="console" />
<appender-ref ref="file" />
</logger>
<logger name="org.hibernate.SQL" additivity="false">
<level value="${log.level}" />
<appender-ref ref="console" />
</logger>
<logger name="org.hibernate.type" additivity="false">
<level value="${log.level}" />
<appender-ref ref="console" />
</logger>
<!--<!– 下面是打印mybatis语句的配置–>-->
<!--<logger name="com.ibatis" additivity="true">-->
<!--<level value="${mybatis.log}" />-->
<!--</logger>-->
<!--<logger name="Java.sql.Connection" additivity="true">-->
<!--<level value="${mybatis.log}" />-->
<!--</logger>-->
<!--<logger name="java.sql.Statement" additivity="true">-->
<!--<level value="${mybatis.log}" />-->
<!--</logger>-->
<!--<logger name="java.sql.PreparedStatement" additivity="true">-->
<!--<level value="${mybatis.log}" />-->
<!--</logger>-->
<!--<logger name="java.sql.ResultSet" additivity="true">-->
<!--<level value="${mybatis.log}" />-->
<!--</logger>-->
<root>
<level value="${log.level}" />
<appender-ref ref="console" />
</root>
</log4j:configuration>
24、本实例还集成了apidoc和quartz,这里就不解释了
25、本列下还有几个实用的工具类,具体可以看源码
26、下载地址 点击打开链接