第一个SpringMVC应用
2017-11-23 本文已影响0人
JaJa大宝剑
最近在图书馆弄了一本《Spring+MyBatis企业应用实战》,想借此机会接触Spring框架,为以后找工作立下基础。
本人用IntelliJ IDEA2017集成工具开发,java版本是1.8.0_121。
File->new->Project...->Maven->Next

写GroupID和ArtifacId,具体的命名规则参考Java包(package)的命名规范,java中package命名规则

然后点Next

然后点Finish完成项目创建
项目目录如下:

然后点左上角File->Project Structure...开始配置项目

为项目添加web模块



接着是修改pom.xml导入maven依赖,这里我把Spring框架的全家桶都搬过来了

接下来编写web.xml

也只能发图片了
接下来新建一个配置文件,xxx-servlet.xml,其中xxx为web.xml中的server-name的值
所以我这里的文件名叫dispatcher-servlet.xml

配置bean

这里按Ctrl+回车,创建ControllerTest类

最后配置服务器


配置服务器



运行

失败了。。。。看错误信息,应该是这个路径下没有index.jsp
最后在web下的WEB-INF下创建pages/index.jsp
最后,点右上角运行

显示如下:

那就ojbk了。。。