1. Webプロジェクトを作成します。
2.インポート必要なjarパッケージ
3.プロファイルのDispatcherServlet、プラグインがインストールされているので、これだけを介してショートカットALT + /へ
<サーブレット> の<servlet-name>のspringMVC </サーブレット名> <servlet- クラス > org.springframework.web.servlet.DispatcherServlet </ servlet- クラス > の<init-param>の の<param-name>のcontextConfigLocation </ param- >名前 springmvc-annotation.xml </ PARAM値>:の<param-value>のクラスパス </ initの-param>の </サーブレット> <のservlet-mapping> の<servlet-name>のspringMVC </サーブレット名> <URL -パターン> *。やる </のurl-pattern> </のservlet-mapping>
4.構成ファイル、XMLファイル(直接XMLにかかるプラグ)を作成し、クラスパスの後にパッケージをスキャンし、ドライブノート書き込まパーサ指導を開き
<?xml version = "1.0"エンコード= "UTF-8"?> <豆のxmlns = "http://www.springframework.org/schema/beans" のxmlns:XSI = "http://www.w3.org / 2001 / XMLスキーマ・インスタンス" のxmlns:コンテキスト = "http://www.springframework.org/schema/context" のxmlns:MVC = "http://www.springframework.org/schema/mvc" XSI:のschemaLocation =" http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd ます。http:// www.springframework.org/schema/beans のhttp:/ /www.springframework.org/schema/beans/spring-beans.xsd ます。http:// www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-4.2.xsd 「> <文脈:コンポーネントスキャン塩基パッケージ =」com.zhiyou.zt.annotation "> </コンテキスト:コンポーネント・スキャン> <MVC:注釈ドリブン/> <MVC:デフォルト -servletハンドラ/> <豆のクラス = "org.springframework.web.servlet.view.InternalResourceViewResolver"> <プロパティ名= "プレフィックス"値= "/ WEB- INF /ビュー/ "> </ property>の <プロパティ名="サフィックス"値="。JSP "> </ property>の </豆> </豆>
5. @ノートが運営するパケットのスキャンでパケットを作成します。
パッケージcom.zhiyou.zt.annotation。 輸入java.text.SimpleDateFormatの。 輸入java.util.Date; インポートのjavax.servlet.http.HttpServletRequest; 輸入javax.servlet.http.HttpSession。 輸入org.springframework.beans.propertyeditors.CustomDateEditor。 輸入org.springframework.stereotype.Controller。 輸入org.springframework.ui.Model。 輸入org.springframework.web.bind.ServletRequestDataBinder。 輸入org.springframework.web.bind.annotation.InitBinder。 輸入org.springframework.web.bind.annotation.RequestMapping。 インポートorg.springframework.web.servlet.ModelAndView; 輸入com.zhiyou.zt.bean.Users。 @Controller @RequestMapping( "/ユーザ" ) パブリック クラス私の{ }
受信したパラメータは、メソッドの名前に対応した個別のパラメータリストが対象ならば、あなたはエンティティクラスに属している必要があり、同じ名前の上に渡さなければなりませんであれば6、パラメータを受け入れます
7.Controllerはリダイレクトに参加ジャンプをリダイレクトする方法:に
8.静的リソースマッピングを解く(springmvc.xmlを加えることができます)
<MVC:デフォルト -servletハンドラ/>