デモバインディングは、デフォルトのデータ型を使用します

HttpServletRequestの使用のタイプに、例えば、デフォルトのデータ・タイプ・バインディングの使用を実証するために、

1. Webプロジェクト、および輸入関連ジャーパッケージを作成します。

2. web.xmlのフロントエンド構成情報スプリングMVCコントローラ

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns="http://java.sun.com/xml/ns/javaee" 
xmlns:web="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaeehttp://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
 id="WebApp_ID" version="2.5">

    <servlet>
    <servlet-name>springmvc</servlet-name>
                 <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
          <param-name>contextConfigLocation</param-name>
          <param-value>classpath:springmvc-config.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>

コンポーネントのスキャナとパーサビューをSpring MVCの設定ファイルを作成し、構成3

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

 

クラスのプロセッサのUserControllerでの作成4。

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

public class UserController {
	@RequestMapping("/selectUser")
	public String selectUser(HttpServletRequest request) {
		String id = request.getParameter("id");
		System.out.println("id="+id);
		return "success";
	}

}

対応するページsuccess.jsp 5.後に成功した訪問を作成します。

     <html>
  <head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>Result page</title>
  </head>
  <body>
        ok
  </body>
     </html> 


6.画面の結果

Webプロジェクトを起動し、http:// localhost:8080にアクセス/第13章/ selectUserのID = 1?

 

 

 

 

 

 

 

 

 

 

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

おすすめ

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