SSM(SpringMVC +春+ MyBatisの)

まず、SpringMVCを構築

  春-webmvc依存プロジェクトのmavenで導入1、

        <! - springmvc - > 
      < 依存> 
          < groupIdを> org.springframework </ groupIdを> 
          < たartifactId >春-webmvc </ たartifactId > 
          < バージョン> 5.1.8.RELEASE </ バージョン> 
      </ 依存関係>    

  2、web.xml構成ファイルは、web.xmlに次のコードを追加します

< サーブレット> 
      < サーブレット名> HelloWeb </ サーブレット名> 
      < サーブレットクラス> 
         org.springframework.web.servlet.DispatcherServlet 
      </ サーブレットクラス> 
      <! - メインのsrc /の位置を修正するspringmvcのコアプロファイル/リソースファイル- > 
      < INIT-PARAM > 
            < PARAM名> contextConfigLocation </ PARAM名> 
            < PARAM-値> CLASSPATH:springmvc.xml </ PARAM値> 
      </ INIT-PARAM >
      <load-on-startup > 1 </ のload-on-startup > 
   </ サーブレット> 
   < のservlet-mapping > 
      < サーブレット名> HelloWeb </ サーブレット名> 
      < のurl-pattern > / </ のurl-pattern > 
   </ servlet-mapping >

   3、設定springmvcコア設定ファイルはsrc /メイン/リソースファイル内のファイルspringmvc.xmlを作成します

    springmvc.xml </ PARAM値>と同じ名:ファイル名は、ファイルの<param-value>のクラスパスをweb.xmlをしなければなりません

< のxmlns = "http://www.springframework.org/schema/beans" 
    のxmlns:コンテキスト= "http://www.springframework.org/schema/context" 
    のxmlns:XSI = "のhttp://www.w3 .ORG / 2001 / XMLスキーマ・インスタンス" 
    のxsi:schemaLocationの=" 
   http://www.springframework.org/schema/beans      
   http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
   のhttp: //www.springframework.org/schema/context 
   http://www.springframework.org/schema/context/spring-context-3.0.xsd」> 

    <! - 扫描com.blb.controller下的注解- > 
    < コンテキスト:コンポーネント・スキャンベースパッケージ=「com.blb.controller」 /> 

    <! -视图解析器- > 
    < 豆の
         クラス= "org.springframework.web.servlet.view.InternalResourceViewResolver" > 
        < プロパティ= "接頭辞" = "/ WEB-INF / JSP /"  /> 
        < プロパティ= "サフィックス" =" JSP」 /> 
    </ ビーン> 

</ >

  4、テストクラスを書きます

  SRC /メイン/ javaファイルにcom.blb.controllerパッケージの作成、パッケージTestControllerでクラスを作成します

パッケージcom.blb.controller。

輸入org.springframework.stereotype.Controller。
輸入org.springframework.web.bind.annotation.RequestMapping。
輸入org.springframework.web.bind.annotation.ResponseBody。

@Controller 
パブリック クラスTestController { 
    
    // 向浏览器返回
    @ResponseBody
     // 拦截地址 
    @RequestMapping( "こんにちは" パブリック文字列のテスト(){
         リターンの"Hello World" ; 
    } 

}

  5、MavenはTomcatとJDKを設定します

< ビルド> 
    < finalName > SSM_T </ finalName > 
    < プラグイン>   
        <! - JDKの配置- > 
        < プラグイン>   
            < groupIdを> org.apache.maven.plugins </ groupIdを> 
            < たartifactId >のmaven-コンパイラプラグイン</ たartifactId >   
            < バージョン> 3.1 </ バージョン>   
            < 構成>   
                < ソース> 1.8 </ ソース>   
                < ターゲット> 1.8 </ ターゲット>   
            </ 設定>   
        </ プラグイン> 
        
        <! - 配置のApache Tomcatの提供的插件- > 
        < プラグイン> 
            < groupIdを> org.apache.tomcat.maven </ groupIdを> 
            < たartifactId > tomcat7-達人-プラグイン</ たartifactId > 
            < バージョン> 2.2 </ バージョン> 
        </ プラグイン> 
     </ プラグイン>  
  </ ビルド>

  6、テスト、打ち上げMavenプロジェクト

    アクセスはlocalhost:8080 /プロジェクト名/ハロー

    ページはハロー世界が成功した表現springmvcを構築表示されます

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  

 

  

おすすめ

転載: www.cnblogs.com/sloth-007/p/11142169.html
おすすめ