国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

Java實現視頻解析系列001:Spring MVC入門:Hello World

2019-11-14 22:35:50
字體:
來源:轉載
供稿:網友
java實現視頻解析系列001:SPRing MVC入門:Hello Worldspring下載

http://projects.spring.io/spring-framework/

安裝spring

有兩種方式建立項目,建議使用maven項目方式,可以更好的控制jar包依賴。

dynamic web project方式

在maven中作如下配置即可(關于maven請參考本站關于maven的文章)。 關于dynamic web project轉換為maven請參考:eclipse java工程跟maven工程的互相轉換 加入spring mvc的方式,直接在pom.xml里面加入以下代碼即可:

<!--spring -->

<dependency>

<groupId>org.springframework</groupId>

<artifactId>spring-core</artifactId>

<version>3.2.13.RELEASE</version>

<type>jar</type>

<scope>compile</scope>

</dependency>

<dependency>

<groupId>org.springframework</groupId>

<artifactId>spring-context</artifactId>

<version>3.2.13.RELEASE</version>

</dependency>

<dependency>

<groupId>org.springframework</groupId>

<artifactId>spring-web</artifactId>

<version>3.2.13.RELEASE</version>

<type>jar</type>

<scope>compile</scope>

</dependency>

<dependency>

<groupId>org.springframework</groupId>

<artifactId>spring-webmvc</artifactId>

<version>3.2.13.RELEASE</version>

</dependency>

注意加入后要更新eclipse項目。 QQ截圖20150113145555

maven項目方式項目結構

2015-01-15_094937

配置與Hello World基于maven

1、修改pom.xml,添加必要依賴

2、添加配置文件

applicationContext.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"

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">

</beans>

SpringMVC-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-3.0.xsd">

<!-- 指定自動掃描路徑 -->

<context:component-scan base-package="com.terwer.player.action"></context:component-scan>

<!-- 視圖解析器,使用jstl -->

<bean id="viewResolver"

class="org.springframework.web.servlet.view.UrlBasedViewResolver">

<property name="viewClass"

value="org.springframework.web.servlet.view.JstlView" />

<property name="prefix" value="/WEB-INF/views/" />

<property name="suffix" value=".jsp" />

</bean>

</beans>

web.xml

<!DOCTYPE web-app PUBLIC

"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"

"http://java.sun.com/dtd/web-app_2_3.dtd" >

<web-app>

<display-name>Archetype Created Web Application</display-name>

<!--spring 監聽器 -->

<listener>

<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>

</listener>

<!--spring MVC攔截器 -->

<servlet>

<servlet-name>springMvc</servlet-name>

<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>

<init-param>

<param-name>contextConfigLocation</param-name>

<param-value>/WEB-INF/SpringMVC-servlet.xml</param-value>

</init-param>

<load-on-startup>1</load-on-startup>

</servlet>

<servlet-mapping>

<servlet-name>springMvc</servlet-name>

<url-pattern>/</url-pattern>

</servlet-mapping>

</web-app>

3、在WEB-INF/views添加頁面index.jsp

QQ截圖20150115100250

傳統方式

參考maven方式

運行在瀏覽器輸入

http://localhost:8080/player/home/index

效果

QQ截圖20150115100702

全部源碼下載

Github download

系列導航

http://www.terwer.com/special.html#用Java實現視頻地址解析


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 偃师市| 枣强县| 宣武区| 淮南市| 井研县| 岗巴县| 丹寨县| 昂仁县| 开化县| 璧山县| 海淀区| 曲阳县| 文化| 马边| 西青区| 黄石市| 东源县| 莱芜市| 原平市| 通渭县| 五峰| 江源县| 井研县| 沙湾县| 盖州市| 水城县| 班戈县| 尉犁县| 萝北县| 饶平县| 武宣县| 城固县| 什邡市| 响水县| 汤阴县| 三门县| 兴业县| 额敏县| 通海县| 杂多县| 基隆市|