環境:
新しいプロジェクトを作成します
[次へ]をクリックします
次に
デフォルトのMavenを選択することもできます。また、デフォルトのMavenのリポジトリアドレスを変更してダウンロード速度を高速化するか、Apache-Maven-3.5.2をローカルにインストールすることもできます。
次に
その後、終了します。
POM依存関係を追加します
作成後のプロジェクトディレクトリは図に表示されます
pom.xmlを開き、依存関係を追加します
<?xml version = "1.0" encoding = "utf-8"?> <project xmlns = "http://maven.apache.org/pom/4.0.0" xmlns:xsi = "http://www.w3.org/2001/xmlschema-instance <http://www.w3.org/2001 xsi:schemalocation = "http://maven.apache.org/pom/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.0.sdsd"> <modelversion> 4.0.0 </modelversion> <グループ<バージョン> 1.0-snapshot </version> <packaging> war </packaging> <name> springmvc maven webapp </name> <! - fixmeそれをプロジェクトのウェブサイトに変更します - > <url> http://www.example.com </url> <properties> <project.buidd. <maven.compiler.source> 1.7 </maven.compiler.source> <maven.compiler.target> 1.7 </maven.compiler.target> </properties> <dependencies> <dependy> <groupid> junit> junit </groupid> <artifactid> <verions> scifactid> </dependency> <! - spring-> <dependency> groupid> org.springframework </groupid> <artifactid> spring-core </artifactid> <バージョン> 4.3.5. release </version> </dependency> <deplency> <groupid> org.spramework <バージョン> 4.3.5.Release </version> </dependency> <dependency> <groupid> org.springframework </groupid> <artifactid> </artifactid> <バージョン> 4.3.5.RELEASE </version> </despency> <! - 解決 - > <artifactid> spring-test </artifactid> <version> 4.2.7.Release </version> </dependency> <seprency> <shivax> javax.servlet </groupid> <artifactid> servlet-api </artifactid> <バージョン> 2.3 </バージョン> </依存関係> <! javax.servlet.jsp.jstl.core.config-> <dependency> <groupid> javax.servlet </groupid> <artifactid> jstl </artifactid> <バージョン> 1.2 </version> </dependency> </dependencies> <build> <finalname> spring bersmvc <bulsminame> <プラグインプラグ>デフォルト(親pomに移動する場合があります) - > <プラグイン> <Artifactid> maven-clean-plugin </artifactid> <バージョン> 3.0.0 </version> </plugin> <! - http://maven.org/ref/current/current/maven-coer - > <Plugin> <Artifactid> maven-resources-plugin </artifactid> <version> 3.0.2 </version> </plugin> <plugin> <artifactid> maven-compiler-plugin </artifactid> <バージョン> 3.7.0 </バージョン> <バージョン> 2.20.1 </version> </plugin> <plugin> <artifactid> maven-war-plugin </artifactid> <version> 3.2.0 </version> </blagin> <plugin> <artifactid> maven-install-plugin </artifactid> <バージョン<artifactid> maven-deploy-plugin </artifactid> <bersion> 2.8.2 </version> </plagin> </pluginins> </pluginmanagement> </build> </project>
対応するディレクトリを作成します
プロジェクトが作成された後、SRC-Mainの下でJavaディレクトリを作成した後、そのディレクトリに新しいパッケージ、Javaクラス、その他のファイルを作成することは不可能です。ディレクトリはアイデアでマークする必要があります。
ファイル - >プロジェクト構造:
これで、対応するディレクトリは作成されていません。ディレクトリを作成した後、対応する注釈を選択します。
(http://wiki.jikexueyuan.com/project/intellij-idea-tutorial/eclipse-java-web-project-introduce.htmlから引用)
ラベルが完了したら、次のディレクトリを作成します。
web.xmlを構成します
Mavenを使用してWeb.xmlを自動的に生成する場合、SpringMVCで渡されたパラメーター値を読み取ることができない場合があります。Web.xmlを変更する必要があります。
元のファイルで直接変更します。
<!doctype web-app public " - // Sun Microsystems、Inc .//dtd Webアプリケーション2.3 // en" "http://java.sun.com/dtd/web-app> <display-name> Archytype作成されたWebアプリケーション< <Servlet-Class> org.springframework.web.servlet.dispatcherservlet </servlet-class> <load-on-startup> 1 </load-on-startup> </servlet-mapping> <servlet-name> mvc-dispatcher </servlet-name> <url-perthn> </url-pertern>
新しいファイル:
<?xml version = "1.0" encoding = "utf-8"?> <web-appバージョン= "2.4" xmlns = "http://java.sun.com/xml/ns/j2ee" xmlns:xsi = "http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation = "http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> <ディスプレイ名>アーキタイプの作成Webアプリケーション< <Servlet-Class> org.springframework.web.servlet.dispatcherservlet </servlet-class> <load-on-startup> 1 </load-on-startup> </servlet-mapping> <servlet-name> mvc-dispatcher </servlet-name> <url-perthn> </url-pertern>
元のファイルWeb-Appのプロパティを交換する必要があることに注意してください
開始時に、デフォルトでは /web-infディレクトリの構成ファイルとしてxxx-servlet.xmlを検索します。 XXXはDispatcherServletの名前であり、パスを手動で構成することもできます。次に、デフォルトの方法を使用します。
Web-INFディレクトリの下にMVC-Dispatcher-servlet.xmlを作成します。
mvc-dispatcher-servlet.xml:
<?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" xsi:schemalocation = " http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd "> <コンテキスト:Component-scan Base-package =" com.xuan. <bean> <プロパティ名= "Viewclass" value = "org.springframework.web.servlet.view.jstlview"/> <Property name = "prefix"/web-inf/views/"/> <プロパティ=" suffix "value ="。jsp "/> </bean> </beans> </beans>
ビューディレクトリを追加:このディレクトリにindex.jspをドラッグします:
コードパス/src/main/javaを編集し、com.xuan.springmvc.controllerパッケージを追加し、maincontroller.javaを追加します。
パッケージcom.xuan.springmvc.controller; import org.springframework.stereotype.controller; Import org.springframework.web.bind.annotation.Requestmapping; @controllerpublic class mainController {@RequestMapping(@RequestMapping(valuation = "/index")public String ")") }}Tomcatサービスを構成します
構成... tomcatパスを構成します
グリーン +サイン、プロジェクトを展開リストに追加します
サーバー名を入力し、Tomcatバージョンを選択します。
グリーン +サイン、プロジェクトを展開リストに追加します
2番目のアイテムを選択することに注意してください。
最後に、Tomcatサービスを開始してデバッグを実行し、結果を表示します。
上記はこの記事のすべての内容です。みんなの学習に役立つことを願っています。誰もがwulin.comをもっとサポートすることを願っています。