SpringMVC - こんにちは、世界のステップの手順:

创建一个のWeb工程
ここに画像を挿入説明
需要导入的瓶包
コモンズ・ログ-1.1.3.jar
のlog4j-1.2.17.jar
春-AOP-4.3.18.RELEASE.jar
春豆-4.3.18.RELEASE.jar
spring-コンテキスト4.3.18.RELEASE.jar
スプリングコア4.3.18.RELEASE.jar
ばね発現4.3.18.RELEASE.jar
ばねウェブ4.3.18.RELEASE.jarの
ばねwebmvc-4.3.18。 RELEASE.jar

ソースディレクトリにSpringmvc.xml config設定ファイルの作成:

<?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-4.3.xsd">

	<!-- 
		配置包扫描
	 -->
	<context:component-scan base-package="com"></context:component-scan>

</beans>

ソースディレクトリの設定で日記log4j.propertiesの設定ファイルを作成します。

# Global logging configuration
log4j.rootLogger=INFO, stdout
# Console output...
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%5p [%t] - %m%n

に構成されたフロントコントローラをweb.xmlに:

<!-- 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>
		<!-- 
			contextConfigLocation初始化参数,用来配置SpringMVC的配置文件路径
		 -->
		<init-param>
			<param-name>contextConfigLocation</param-name>
			<param-value>classpath:springmvc.xml</param-value>
		</init-param>
		<!-- 
			load-on-startup 标签 配置当Web工程启动的时候。就创建Servlet程序实例。
		 -->
		<load-on-startup>1</load-on-startup>
	</servlet>
	<!-- 
		servlet-mapping 标签 配置Servlet程序的访问地址
	 -->
	<servlet-mapping>
		<servlet-name>springDispatcherServlet</servlet-name>
		<!-- 
			/ 表示将所有请求都转交给SpringMVC处理
		 -->
		<url-pattern>/</url-pattern>
	</servlet-mapping>

構成コントローラコントローラ(コントローラベースのコントローラは、要求メソッドを処理それぞれが要求を処理するために使用されます)

@Controller
public class HelloController {

	/**
	 * hello方法处理用户的请求<br/>
	 * @RequestMapping("/hello") 表示给当前方法配置一个访问地址。<br/>
	 * 	/hello 表示http://ip:port/工程名/hello <br/>
	 */
	@RequestMapping("/hello")
	public String hello() {
		System.out.println("spring mvc 的 hello world!");
		/**
		 * 返回值表示转发到 http://ip:port/工程名/ok.jsp路径
		 */
		return "/ok.jsp";
	}
	
}

JSPページが必要になります。

index.jspページ

	<body>
		<a href="http://localhost:8080/spring_mvc_hello/hello">hello请求</a>
	</body>

ok.jspページ

	<body>
		请求完成!!!
	</body>

おすすめ

転載: blog.csdn.net/No_mingzi/article/details/92652485