IntelliJ IDEA创建Spring Maven 项目
来源:互联网 发布:绝地求生 dx12优化 编辑:程序博客网 时间:2024/06/05 06:55
转载请注明出处:
http://blog.csdn.net/aa464971/article/details/78250259
Android交流群:146262062
创建新项目
- 创建一个新项目,
Maven
-Create from archetype
,选中maven-archetype-webapp
这个archetype
- 输入GroupId和ArtifactId
- 输入项目名称并选择项目存放的路径
配置项目结构
- 进入项目结构配置界面,
File
-Project Structure
- 选中
Modules
; - 在
main
下创建java
文件夹; - 在
webapp
-WEB-INF
下创建views
文件夹
- 标记
java
文件夹为Sources
- 标记
resources
文件夹为Resources
- 最终的项目结构如图
引入Spring
打开pom.xml,引入Spring
<!--jstl--><dependency> <groupId>javax.servlet.jsp.jstl</groupId> <artifactId>jstl-api</artifactId> <version>1.2</version></dependency><!--spring--><dependency> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> <version>4.3.1.RELEASE</version></dependency><dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>4.3.1.RELEASE</version></dependency>
如果提示是否需要开启自动导入,选择Enable Auto-Import
,否则更改了pom.xml不会自动更新
配置web.xml
<web-app> <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/dispatcher-servlet.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <servlet> <servlet-name>dispatcher</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>dispatcher</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping></web-app>
配置Spring
在WEB-INF
下新建dispatcher-servlet.xml
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd"> <!--扫描包路径--> <context:component-scan base-package="com.example" /> <!-- 开启注解 --> <context:annotation-config /> <mvc:annotation-driven /> <!-- 静态资源(js、image等)的访问 --> <mvc:default-servlet-handler /> <!--ViewResolver 视图解析器--> <!--用于支持Servlet、JSP视图解析--> <bean id="jspViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="viewClass" value="org.springframework.web.servlet.view.JstlView" /> <property name="prefix" value="/WEB-INF/views/" /> <property name="suffix" value=".jsp" /> </bean></beans>
配置访问路径与视图
- 创建一个类命名HomeController,并注解
@Controller
,这个类就会被当成Controller - 再加上访问路径的注解
@RequestMapping("/home")
- 在HomeController内创建一个hello方法,在方法上注解
@RequestMapping("/hello")
,这样当访问http://localhost:8080/spring-helloworld/home/hello
的时候,就会执行这个方法 - 最后
return "hello"
,这样执行完hello方法后会跳转到hello.jsp(hello.jsp需要建在WEB-INF
-views
下)
配置Tomcat
添加一个Tomcat服务 +
- Tomcat Server
- Local
切换到Deployment
,+
- Artifact...
添加当前项目的war,并设置项目访问路径为spring-helloworld
运行Tomcat
运行完成后,在浏览器访问http://localhost:8080/spring-helloworld/home/hello
,就进入到hello.jsp了
阅读全文
0 0
- Intellij IDEA 2017 创建Spring Maven项目
- IntelliJ IDEA创建Spring Maven 项目
- Intellij idea+maven创建项目
- Intellij IDEA创建maven项目
- Intellij Idea创建Maven项目
- Intellij IDEA 15.0.2创建Spring MVC Maven项目
- IntelliJ idea创建Spring MVC的Maven项目
- IntelliJ IDEA上创建Maven Spring MVC项目
- IntelliJ IDEA上创建Maven Spring MVC项目
- IntelliJ IDEA上创建maven Spring MVC项目
- IntelliJ IDEA上创建Maven Spring MVC项目
- IntelliJ IDEA上创建Maven Spring MVC项目
- IntelliJ IDEA上创建Maven Spring MVC项目
- IntelliJ idea创建Spring MVC的Maven项目
- IntelliJ IDEA上创建Maven Spring MVC项目
- IntelliJ IDEA上创建maven Spring MVC项目-自动
- IntelliJ IDEA上创建Maven Spring MVC项目
- IntelliJ IDEA上创建Maven Spring+SpringMVC+Hibernate项目
- 第十章 代理商拓扑结构【笔记】
- python学习记录(1)
- c/c++中嵌入汇编
- 【阅读】数据可视化之美——用专家的眼光洞察数据
- linux解压*.tgz出现异常的解决办法
- IntelliJ IDEA创建Spring Maven 项目
- apk反编译
- Unity 下载图片并保存(WWW)
- gcov和lcov
- HDU2680 Choose the best route (最短路)(Dijkstra算法)
- Httpservlet源码及实现机制详解
- java.lang.NoSuchMethodError: redis.clients.jedis.JedisShardInfo.setTimeout(I)V
- Advanced Django Models
- 2015美国闪存峰会特稿——NVMe + RDMA = 非凡的性能!