千家信息网

如何使用idea构建springmvc项目

发表于:2024-09-22 作者:千家信息网编辑
千家信息网最后更新 2024年09月22日,这篇"如何使用idea构建springmvc项目"文章的知识点大部分人都不太理解,所以小编给大家总结了以下内容,内容详细,步骤清晰,具有一定的借鉴价值,希望大家阅读完这篇文章能有所收获,下面我们一起来
千家信息网最后更新 2024年09月22日如何使用idea构建springmvc项目

这篇"如何使用idea构建springmvc项目"文章的知识点大部分人都不太理解,所以小编给大家总结了以下内容,内容详细,步骤清晰,具有一定的借鉴价值,希望大家阅读完这篇文章能有所收获,下面我们一起来看看这篇"如何使用idea构建springmvc项目"文章吧。

1.首先我们可以创建maven项目,file-> new ->project->maven,现则createa form archetype,这样可以生成maven的一些构建插件

2.写项目名,finish即可

3.项目结构整体如下

4.改造成我们常用的maven结构,在main下新建java包和resources包,把java包标记成根路径,resources标记成资源根路径包

4.导入springmvc的pom,整体pom如下

  4.0.0  com.zy  springmvc-demo2  1.0-SNAPSHOT  war  springmvc-demo2 Maven Webapp    http://www.example.com      UTF-8    1.7    1.7    5.1.6.RELEASE                      org.springframework      spring-webmvc      ${spring.version}              org.springframework      spring-test      ${spring.version}                  junit      junit      4.11      test                      org.slf4j      slf4j-log4j12      1.8.0-alpha0      test                  javax.servlet.jsp      jsp-api      2.2              javax.servlet      jstl      1.2              javax.servlet      javax.servlet-api      3.1.0            springmvc-demo2                            maven-clean-plugin          3.1.0                                  maven-resources-plugin          3.0.2                          maven-compiler-plugin          3.8.0                          maven-surefire-plugin          2.22.1                          maven-war-plugin          3.2.2                          maven-install-plugin          2.5.2                          maven-deploy-plugin          2.8.2                    

4.1这里我们只导入了 spring-mvc的依赖,他会自动导入spring的相关包,打开maven导图你可以看到springmvc会自动依赖spring相关的jar,也就是说导入了mvc的包,他会自动把spring相关的包也导入进来,这就是maven的依赖管理的好处

5.在web.xml中写DispatcherServlet,这是springmvc的servlet,指定了springmvc的配置文件地址在classpath:spring-mvc.xml,spring容器使用ContextLoaderListener制定了spring配置文件在classpath:applicationContext.xml

  Archetype Created Web Application            contextConfigLocation        classpath:applicationContext.xml                org.springframework.web.context.ContextLoaderListener                dispatcher        org.springframework.web.servlet.DispatcherServlet                    contextConfigLocation            classpath:spring-mvc.xml                1                dispatcher        /*    

6.springmvc得配置文件

                                                                              

7.application配置文件

                        

8.根据springmvc.xml配置文件,在WEB-INF下新建views包和index.jsp

9.新建com.zy.controller包,并写一个controller类进行

10.配置tomcat服务器

11.启动tomcat服务器,http://localhost:8080/hello,这是测试jsp页面的,进行测试

12.在浏览器输入刚才controller的请求地址,看结果

12.顺利完成springmcx基于xml配置的构建。

以上就是关于"如何使用idea构建springmvc项目"这篇文章的内容,相信大家都有了一定的了解,希望小编分享的内容对大家有帮助,若想了解更多相关的知识内容,请关注行业资讯频道。

0