创建项目
- 使用 IDEA 建立一个 Maven 项目。
- 打开
pom.xml
文件,修改
<packaging>war</packaging>
- 建立如下目录:
选中项目,点击刷新即可。
加入依赖
<?xml version="1.0" encoding="UTF-8"?>
<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>org.yun</groupId>
<artifactId>ssm</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>ssm</name>
<description>SpringMVC + Spring + MyBatis</description>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<!--MyBatis-->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.5.0</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>2.0.0</version>
</dependency>
<dependency>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-core</artifactId>
<version>1.3.7</version>
</dependency>
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>5.1.8</version>
</dependency>
<!--数据库驱动-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
<version>5.1.41</version>
</dependency>
<!--Spring-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<scope>test</scope>
</dependency>
<!--JSON-->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.9.8</version>
</dependency>
<!--JSR3033-->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>6.0.16.Final</version>
</dependency>
<!--Java Web -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<!--测试-->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<!--日志-->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.26</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.26</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<!--将jquery以jar包的形式引入-->
<!--<script src="${ctx}/webjars/jquery/3.3.1-2/jquery.min.js"></script>-->
<dependency>
<groupId>org.webjars</groupId>
<artifactId>jquery</artifactId>
<version>3.3.1-2</version>
</dependency>
</dependencies>
<!--统一Spring的版本-->
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>5.1.5.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
创建包目录、配置文件
controller 包
存放 web mvc 控制器dao 包
存放 MBG 自动生成的 mapper 接口model 包
存放 MBG 自动生成的实体类service 包
存放业务逻辑代码mapper
存放 MBG 自动生成的 xxxMapper.xml 文件data.sql
存放数据库测试数据jdbc.properties
存放数据库连接信息schema.sql
存放数据库表的建表语句spring.xml
Spring 容器配置文件spring-mvc.xml
Spring MVC 配置文件mbg.xml
mybatis-generator(MBG) 配置文件
查看项目结构图
命令:tree>tree.txt
卷 LENOVO 的文件夹 PATH 列表
卷序列号为 0E7D-ED82
D:.
├─.idea
│ └─dataSources
├─src
│ ├─main
│ │ ├─java
│ │ │ └─org
│ │ │ └─yun
│ │ │ └─ssm
│ │ │ ├─controller
│ │ │ ├─dao
│ │ │ ├─model
│ │ │ └─service
│ │ ├─resources
│ │ │ └─mapper
│ │ └─webapp
│ │ ├─static
│ │ │ └─js
│ │ └─WEB-INF
│ │ └─views
│ └─test
│ └─java
│ └─org
│ └─yun
│ └─ssm
│ └─test
└─target
├─classes
│ └─mapper
├─generated-sources
│ └─annotations
├─generated-test-sources
│ └─test-annotations
├─ssm-1.0-SNAPSHOT
│ ├─META-INF
│ ├─static
│ │ └─js
│ └─WEB-INF
│ ├─classes
│ │ ├─mapper
│ │ └─org
│ │ └─yun
│ │ └─ssm
│ │ ├─controller
│ │ ├─dao
│ │ ├─model
│ │ └─service
│ ├─lib
│ └─views
└─test-classes
└─org
└─yun
└─ssm
└─test
来源:oschina
链接:https://my.oschina.net/u/2899526/blog/3032942