标签:fas mvc scan 依赖 步骤 .com ram 实例 map
SpringMvc作为Spirng家族中的一个重要模块,已经成为我们日常开发中最主流的控制层框架之一。精简的用法,以及零配置的注解使用,加上天生与Spring的无缝集成,都是SpringMvc的巨大优势。SpringMvc入门,HelloWorld实例:
步骤:
1)创建一个maven的war工程
2)maven引入相应的jar包,我们这里只引入Springmvc的依赖包spring-webmvc 和servlet-api
<!-- https://mvnrepository.com/artifact/org.springframework/spring-webmvc -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.3.7.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.servlet/jstl -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.servlet/servlet-api -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
引入后的环境:
3)创建包com.sky.main 以及 此包下的类DemoServer.java
4)web.xml文件中配置SpringMvc的入口,前端控制器:
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
5)配置Springmvc的配置文件
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd" >
<!-- 启动spring mvc注解 -->
<mvc:annotation-driven/>
<!-- 添加注解扫描的包 -->
<context:component-scan base-package="com.sky.*"/>
</beans>
6)启动tomcat测试springmvc
打开谷歌浏览器输入:http:127.0.0.1:8080/fastjson_springmvc/demo.do
控制台输出:
以上是简要的搭建了一下Springmvc的开发环境,下面介绍一下fastjson
springmvc与fastjson的暴力美学,仅以此向温少致敬!
标签:fas mvc scan 依赖 步骤 .com ram 实例 map
原文地址:http://www.cnblogs.com/yujiwei/p/6880764.html