1.创建Maven工程,具体过程详见https://www.jianshu.com/p/0fc4a5b2621e
2.引入项目所需jar包。
地址:http://mvnrepository.com
Spring,SpringMVC,Mybatis,数据库连接池,驱动包,其他(jstl,servlet-api,junit)
Spring Web MVC
Spring JDBC
Spring Aspects:Spring面向切面编程
MyBatis
MyBatis Spring
C3P0:数据库连接池
MySQL Connector/J:数据库连接驱动
JSTL:JSP标签库
JavaServlet(TM) Specification
JUnit:单元测试
Apache Log4j :日志
<!--引入项目依赖的jar包 -->
<dependencies>
<!-- Spring,SpringMVC -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.3.18.RELEASE</version>
</dependency>
<!-- Spring,JDBC -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>4.3.18.RELEASE</version>
</dependency>
<!-- Spring面向切面编程 -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
<version>4.3.18.RELEASE</version>
</dependency>
<!-- Mybatis -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.4.6</version>
</dependency>
<!-- Mybatis 整合 Spring-->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>1.3.1</version>
</dependency>
<!-- 数据库连接池,驱动-->
<dependency>
<groupId>com.mchange</groupId>
<artifactId>c3p0</artifactId>
<version>0.9.5.2</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>6.0.6</version>
</dependency>
<!-- jstl,servlet-api,junit,log4j -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
</dependencies>
完成后即可在Maven Dependencies 中看到引入的jar包:
注:你如果编写过servlet就知道要用到HttpServletRequest和HttpServletResponse等对象,这些对象都是要靠servlet-api.jar包才能使用的。
如果你安装了Tomcat,这个jar包一般在tomcat安装目录\lib 文件夹下面有,当你把web项目部署到tomcat,会自动加载这个jar包来识别Serlvet一些对象。为了避免冲突,项目中的jar依赖后面要加:
<scope>provided</scope>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
3.引入Bootstrap前端框架
(1)下载地址:https://v3.bootcss.com/getting-started/#download
(2)webapp下新建目录static,放入bootstrap和jquery,新建index.jsp
(3)index.jsp中引入bootstrap
<!-- jQuery (Bootstrap 的所有 JavaScript 插件都依赖 jQuery,所以必须放在前边) -->
<script src="static/js/jquery-3.3.1.min.js"></script>
<!-- Bootstrap -->
<script src="static/bootstrap-3.3.7-dist/js/bootstrap.min.js"></script>
<link href="static/bootstrap-3.3.7-dist/css/bootstrap.min.css" rel="stylesheet">
网友评论