注釈ベースのSpring MVCアプリケーション

Webプロジェクト、ジャーパッケージの導入を作成します。1.

2. [追加の設定ファイルスキャン設定springmvc-config.xmlの注釈、ビューリゾルバ定義(日食でこのエラーコードを、しかし実行には影響しません)

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
 xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
 xmlns:p="http://www.springframework.org/schema/p"
 xsi:schemaLocation=" 
          http://www.springframework.org/schema/beans
          http://www.springframework.org/schema/beans/spring-beans-4.3.xsd 
          http://www.springframework.org/schema/tx
          http://www.springframework.org/schema/tx/spring-tx-4.3.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"
 default-autowire="byName">
        <context:component-scan base-package = "com.itheima.controller"/>
        <bean id = "viewResolver" class = "org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name = "prefix" value = "/WEB-INF/jsp/"/>
        <property name = "suffix" value = ".jsp"/>
        
        </bean>
        </beans>

3.書き込みFirstControllerクラスは、クラスやメソッドに適切な注釈を追加します

package com.itheima.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.ModelAndView;


@Controller
@RequestMapping(value = "/hello")
public class FirstController {
	@RequestMapping(value = "/firstController")
	public String handleRequest(HttpServletRequest request, HttpServletResponse response, Model model) throws Exception{
		
		model.addAttribute("msg", "This is my second programe");
		return "first";
	}

}

4.展開して、プロジェクトを開始し、アドレスでhttp:// localhost:8080 /にアクセス第12章/ハロー/ firstController

ページエラーした場合、再実行し、オープン日食では、日食を閉じます。

 

公開された376元の記事 ウォンの賞賛172 ・は 90000 +を見て

おすすめ

転載: blog.csdn.net/Eider1998/article/details/104179293