工具:

    1.IntelliJ IDEA2017.2.1

    2.jdk 1.8.0_144

    3.apache-tomcat-7.0.77


1.点击file,new,project,新建一个项目(也就是在工作空间中创建一个目录)

idea创建简单spring mvc工程


2.选择spring,勾选spring mvc

idea创建简单spring mvc工程


3.finish

idea创建简单spring mvc工程


4.完成之后项目目录结构如下

idea创建简单spring mvc工程


5.配置Tomcat

idea创建简单spring mvc工程


第一次,需要配置Tomcat路径

idea创建简单spring mvc工程


idea创建简单spring mvc工程


以后每次新建项目需要进行如下操作


idea创建简单spring mvc工程


idea创建简单spring mvc工程


6.这个时候启动的时候项目会报错,原因是找不到jar包,通过查看out目录可以知道,,所有的jar包都没有输出

idea创建简单spring mvc工程


那么我们需要手动将jar包输出,F4配置项目

idea创建简单spring mvc工程


idea创建简单spring mvc工程


点击fix,选择添加所有依赖即可

idea创建简单spring mvc工程


如图,新出现了lib目录,警告消失,这时候项目可以正常启动了

idea创建简单spring mvc工程


我们也可以手动添加

idea创建简单spring mvc工程



idea创建简单spring mvc工程


idea创建简单spring mvc工程

7.到这里项目已经可以正常启动了,可以正常访问http://localhost:8080/,接下来我们写一个DemoController,会发现找不到HttpServletRequest等等,因为还没有servlet等等的相关jar包,添加的方式如下

按F4可以看到我们项目的所有配置,点击+,把Tomcat的运行库加上

idea创建简单spring mvc工程


idea创建简单spring mvc工程


idea创建简单spring mvc工程


到这里一切都OK了

相关文章: