大战熟女丰满人妻av-荡女精品导航-岛国aaaa级午夜福利片-岛国av动作片在线观看-岛国av无码免费无禁网站-岛国大片激情做爰视频

專(zhuān)注Java教育14年 全國(guó)咨詢(xún)/投訴熱線(xiàn):400-8080-105
動(dòng)力節(jié)點(diǎn)LOGO圖
始于2009,口口相傳的Java黃埔軍校
首頁(yè) hot資訊 SpringMVC的配置文件方法:使用注解的方法

SpringMVC的配置文件方法:使用注解的方法

更新時(shí)間:2021-09-09 11:53:37 來(lái)源:動(dòng)力節(jié)點(diǎn) 瀏覽1135次

1.需要添加相應(yīng)的jar包。

如果要配置MVC的話(huà)是需要添加Spring-web和Spring-webmvc的。如果沒(méi)有可以去官網(wǎng)下載 https://repo.spring.io/libs-release-local/

2.創(chuàng)建spring.xml文件

這個(gè)是spring的配置文件。

<?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:mvc="http://www.springframework.org/schema/mvc"
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:aop="http://www.springframework.org/schema/aop"
	xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd
		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-4.3.xsd
		http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.3.xsd">
<context:component-scan base-package="com.etc.controller"></context:component-scan>
<!-- 這是靜態(tài)處理 -->
<mvc:default-servlet-handler/>
<mvc:annotation-driven></mvc:annotation-driven>
<!--  -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"></property>
<property name="prefix" value='back/'></property>
<property name="suffix" value=".jsp"></property>
</bean>
</beans>

3.修改web.xml文件

需要加入前端控制器,DispatcherSerclet,和相關(guān)的影響。還有Filter(可不加)是一個(gè)過(guò)濾器,可以過(guò)濾編碼和權(quán)限等

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd" id="WebApp_ID" version="4.0">
  <display-name>springmvc</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
  <!-- 前端控制器 -->
  <!-- The front controller of this Spring Web application, responsible for handling all application requests -->
	<servlet>
		<servlet-name>springDispatcherServlet</servlet-name>
		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
		<init-param>
			<param-name>contextConfigLocation</param-name>
			<!--這個(gè)是在開(kāi)始的時(shí)候初始化spring,xml-->
			<param-value>classpath:spring.xml</param-value>
		</init-param>
		<load-on-startup>1</load-on-startup>
	</servlet>
	
<!-- 映射 -->
	<!-- Map all requests to the DispatcherServlet for handling -->
	<servlet-mapping>
		<servlet-name>springDispatcherServlet</servlet-name>
		<url-pattern>/</url-pattern>
	</servlet-mapping>
	<!-- 這個(gè)是filter 可以過(guò)濾編碼和權(quán)限問(wèn)題 -->
	<filter>
	<filter-name>Filter</filter-name>
	<!-- 這個(gè)是 spring實(shí)現(xiàn)的filter -->
	<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
	<init-param>
	<!-- 初始化encoding 為utf-8 -->
	<param-name>encoding</param-name>
	<param-value>UTF-8</param-value>	
	</init-param>
	<init-param>
	<!-- 這個(gè)是設(shè)置response的編碼問(wèn)題,這這個(gè)類(lèi)里如果forceEncoding是ture 的話(huà),response和request的編碼都設(shè)置 -->
	<param-name>forceEncoding</param-name>
	<param-value>true</param-value>
	</init-param>
	</filter>
	<filter-mapping>
	<filter-name>Filter</filter-name>
	<url-pattern>/*</url-pattern>
	</filter-mapping>
</web-app>

4.創(chuàng)建創(chuàng)建控制類(lèi)

主要有三種方法,他們會(huì)有一些不同和區(qū)別。

@RestController
public class Hello {
	@GetMapping("s")
	public String say(String name) {				
		return "hello"+name;
	}
}
@Controller
public class Hello2 {
	@GetMapping("say")
	public String say(String name) {				
		return "hello";
	}
}
@Controller
public class Hello3 {
	@GetMapping("say3")
	public ModelAndView say() {
		ModelAndView mv = new ModelAndView("hello2");
		String name="abc";
		mv.addObject("name", name);		
		return mv;
	}
}

以上就是動(dòng)力節(jié)點(diǎn)小編介紹的"SpringMVC的配置文件方法:使用注解的方法",希望對(duì)大家有幫助,想了解更多可查看SpringMVC教程。動(dòng)力節(jié)點(diǎn)在線(xiàn)學(xué)習(xí)教程,針對(duì)沒(méi)有任何Java基礎(chǔ)的讀者學(xué)習(xí),讓你從入門(mén)到精通,主要介紹了一些Java基礎(chǔ)的核心知識(shí),讓同學(xué)們更好更方便的學(xué)習(xí)和了解Java編程,感興趣的同學(xué)可以關(guān)注一下。

提交申請(qǐng)后,顧問(wèn)老師會(huì)電話(huà)與您溝通安排學(xué)習(xí)

免費(fèi)課程推薦 >>
技術(shù)文檔推薦 >>
主站蜘蛛池模板: 亚洲 欧美精品 | 一区亚洲| 热re99久久精品国产99热 | 国产精品一区二区久久精品涩爱 | 欧美区一区二 | 色拍自拍亚洲综合在线 | 亚州精品一区二区三区 | 一级做a爰片性色毛片2021 | 99精品视频看国产啪视频 | 精品在线视频播放 | 97人人在线 | 国产精品a v 免费视频 | 欧美色老太婆 | 日本不卡视频网站 | 久久久久亚洲视频 | 91精品国产免费久久久久久 | 久久www免费人成看国产片 | 日韩色区 | 精品一区二区久久久久久久网精 | 成人网18免费网站在线 | 97久久国产一区二区三区四区 | 成人欧美一级毛片免费观看 | 日韩午夜在线视频 | 国产精品日韩欧美久久综合 | 最近中文字幕无吗高清视频 | 亚洲欧美在线一区 | 就草草在线观看视频 | 青草在线视频 | 91不卡在线精品国产 | 亚洲成人在线免费 | 欧美色爱综合 | 久久国产大片 | 一级黄色α片 | 99热这里只有精品首页精品 | 香蕉依人 | 神马影院伦理我不卡 | 99热久久这里只有精品 | 日产国语一区二区三区在线看 | 911国产在线观看精品 | 久久精品中文字幕第一页 | 99这里有精品视频 |