idea搭建springmvc maven项目

jdk:1.8

maven:Bundled (Maven 3)

idea版本:

开始搭建第一个springmvc maven项目

1.点击File->New->Project

2.选择maven->勾选Create from archetype->选中 maven-archetype-webapp->点击next

3.Name:项目名称   Location:本地工作空间   填写后点击next

4.我没下maven所有就用了默认的,如果本地有的话就使用本地的,填好后finish

5.创建好的项目结构如下

5.1.pom.xml如下:

<?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.example</groupId>
<artifactId>weChat</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging> <name>weChat Maven Webapp</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
<spring.version>4.2.4.RELEASE</spring.version>
</properties> <dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<!-- Spring -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency> <dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency> <dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.8.7</version>
</dependency>
</dependencies> <build>
<finalName>weChat</finalName>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_war_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
<!--Tomcat7插件 -->
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<uriEncoding>UTF-8</uriEncoding>
<path>/weChat</path>
<port>8080</port>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
 5.2.web.xml如下:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<display-name>Archetype Created Web Application</display-name>
<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:mvc.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springMvc</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
</web-app>

6.这个时候你会发现少了目录,选中项目右键->new->Directory

7.这个时候你会发现有这四个你熟悉的目录,我只需要前面两个即可

8.resource下创建mvc.xml文件,我的如下:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<display-name>Archetype Created Web Application</display-name>
<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:mvc.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springMvc</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
</web-app>
9.创建controller类
package com.test.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping; @Controller
public class HelloController {
@RequestMapping(value = "/test")
public String test(){
return "test";
}
}
10.WEB-INF下创建views文件夹后添加test.jsp页面
<html>
<body>
<h2>Hello World! weChat</h2>
</body>
</html>
11.现在的目录如下:


12.使用Tomcat7插件配置启动项目;点击Add Configuration

13.点击+-》点击Maven

14.Name:项目名称  Working directory:工作空间    Command line:启动命令  填完后点击ok

15.启动成功

16,访问页面

http://localhost:8080/weChat/

17.访问页面http://localhost:8080/weChat/test.do

18.一个springmvc项目就创建成功啦,你也试试吧。。。。。。


  

												

最新文章

  1. iOS导航栏的正确隐藏方式【转】
  2. Creating a SharePoint BCS .NET Connectivity Assembly to Crawl RSS Data in Visual Studio 2010
  3. 如何用Android Studio打多包名APK
  4. 当git上文件大小写重命名的修改时(git大小写敏感/默认不敏感),如何提交
  5. 简单实用的JQuery弹出层
  6. Java数据持久层框架 MyBatis之背景知识一
  7. CSS3之box-shadow
  8. openstack的最简单安装
  9. 网络协议 10 - Socket 编程(上):实践是检验真理的唯一标准
  10. No space left on device Linux系统磁盘空间已满
  11. Linux三个网络监视器之《二》——nethogs
  12. 【专栏学习】APM——异步编程模型(.NET不推荐)
  13. 树莓派3中编译Opencv3.4.10
  14. Scala学习笔记(三):==,eq与equals的区别
  15. javascript定时器使用
  16. Git和Jenkins日记之没有新提交代码
  17. 9、redis之事务2-Jedis的八种调用方式(事务、管道、分布式)介绍
  18. 在Django中使用Q()对象
  19. 51nod1821 最优集合 贪心
  20. react的一些思考

热门文章

  1. WLC-生成CSR操作
  2. jxl读取设置过数据有效性的xls文件报错
  3. java之md5加密算法
  4. javascript对象创建及继承
  5. 基于Struts2+Hibernate开发小区物业管理系统 附源码
  6. 03.使用私有构造方法或枚类实现 Singleton 属性
  7. 笔记-AJAX
  8. C程序的执行和当前进程的结束
  9. Microsoft Cortana移动版除美国市场外不再可用
  10. JVM虚拟机内存溢出垃圾收集及类加载机制总结