如果创建项目报错,可以参照《使用eclipse创建Web工程》
如果Maven配置出现问题,可以参照《使用Maven配置阿里云镜像与JDK》
一、创建Maven工程
在Eclipse中创建一个简单的Maven工程,记得将打包方式设置为war包方式。
引入项目依赖包
项目中使用到的jar包 | 说明 | 使用版本 | 坐标 |
---|---|---|---|
pageHelper | 分页插件 | 5.0.0 | 地址 |
mybatis-generator-core | mybatis的逆向工程 | 1.3.5 | 地址 |
spring-webmvc | 包含SpringMVC框架相关的所有类。 | 4.3.7 | 地址 |
jackson-databind | 是基于Java平台的一套数据处理工具,可以进行Java Json解析。 | 2.8.8 | 地址 |
hibernate-validator | JSR303数据校验支持(tomcat7以下的服务器需要额外替换el表达式) | 5.4.1 | 地址 |
spring-jdbc | 对JDBC 的简单封装 | 4.3.7 | 地址 |
spring-aspects | Spring提供的对AspectJ框架的整合 | 4.3.7 | 地址 |
spring-test | 对JUNIT等测试框架的简单封装 | 4.3.7 | 地址 |
mybatis | mybatis依赖 | 3.4.2 | 地址 |
mybatis-spring | mybatis与spring整合 | 1.3.1 | 地址 |
c3p0 | C3P0是一个开源的连接池。 | 0.9.1 | 地址 |
mysql-connector-java | MySQL数据库驱动。 | 5.1.41 | 地址 |
jstl | jstl依赖 | 1.2 | 地址 |
javax.servlet-api | 注意:此jar包推荐设置为provided,避免与tomcat中的servlet冲突。 | 3.0.1 | 地址 |
junit | 测试使用的依赖 | 4.12 | 地址 |
本项目完整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.gql</groupId>
<artifactId>ssm-crud</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<dependencies>
<!-- SpringMVC、Spring -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.3.7.RELEASE</version>
</dependency>
<!-- Spring AOP -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
<version>4.3.7.RELEASE</version>
</dependency>
<!-- Spring test -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>4.3.7.RELEASE</version>
<scope>provided</scope>
</dependency>
<!-- Mybatis -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.4.2</version>
</dependency>
<!-- Mybatis整合Spring的适配包 -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>1.3.1</version>
</dependency>
<!-- mybatis的逆向工程MBG -->
<dependency>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-core</artifactId>
<version>1.3.5</version>
</dependency>
<!-- pageHelper分页插件 -->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>5.0.0</version>
</dependency>
<!-- 数据处理工具:可以返回Json字符串的支持 -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.8.8</version>
</dependency>
<!-- 后端校验:hibernate的JSR303 -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>5.4.1.Final</version>
</dependency>
<!-- Spring Jdbc -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>4.3.7.RELEASE</version>
</dependency>
<!-- mysql数据库驱动 -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.41</version>
</dependency>
<!-- c3p0数据库连接池 -->
<dependency>
<groupId>c3p0</groupId>
<artifactId>c3p0</artifactId>
<version>0.9.1</version>
</dependency>
<!-- jstl依赖 -->
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<!-- servlet-api,需要设置为provided,避免与tomcat冲突 -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
<!-- junit测试依赖 -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
三、引入Bootstrap框架和jQuery
本项目使用Bootstrap3.3.7版本,下载Bootstrap框架请前往:Bootstrap官网。
在webapp文件夹下创建一个static文件夹,引入Bootstrap框架后,再创建js文件夹,引入jQuery文件(这个需要自行下载)。
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>员工列表</title>
<%
pageContext.setAttribute("APP_PATH", request.getContextPath());
%>
<script
src="${APP_PATH }/static/bootstrap-3.3.7-dist/js/bootstrap.min.js"></script>
<link
href="${APP_PATH }/static/bootstrap-3.3.7-dist/css/bootstrap.min.css"
rel="stylesheet">
<script type="text/javascript"
src="${APP_PATH }/static/js/jQuery-3.4.1.js"></script>
</head>
<body>
</body>
</html>