建立maven web项目默认生成的pom.xml文件:(ProjectName项目名称,com.li设置的包名)
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.li</span></groupId>
<artifactId>ProjectName</span></artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>ProjectName</span> Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</span></version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>ProjectName</span></finalName>
</build>
</project>
建议更改Junit (单元测试@Test)为4.11以后版本:
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
web项目必备: servlet-api / jsp-api / jstl (数字为版本信息)
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</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>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
<scope>runtime</scope>
</dependency>
log4j 日志:
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
tomcat 插件:
<build>
<finalName>springMVC_JDBC</finalName>
<plugins>
<!-- tomcat插件 -->
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<!--运行端口(可自行设置改变端口) -->
<port>8080</port>
<!-- 访问路径 eg: http://localhost:8080/spring -->
<path>/spring</path>
<!--字符编码 -->
<uriEncoding>UTF-8</uriEncoding>
<!-- 服务器 -->
<server>tomcat</server>
</configuration>
</plugin>
</plugins>
</build>
连接数据库,进行增删改查:
<!-- spring-jdbc -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>4.3.10.RELEASE</version>
</dependency>
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>1.4</version>
</dependency>