1.アイデアを使用して新しいプロジェクトを作成します
2。Mavenプロジェクトを作成することを選択します
3. GroupIDとArtifactidに記入します
4.プロジェクト名に記入してください。これは、前のステップのArtifactidと同じです。[完了]をクリックします。
5.新しく構築されたディレクトリは、次のようにMavenディレクトリ構造です
6.ディレクトリ構造を改善し、WebApp、Web-INFディレクトリ、web.xmlファイルを追加します
7. IdeaのMaven設定を変更します。 Mavenのデフォルトのローカルリポジトリは、将来の利便性のために、Disk Cに保存されます。可能な限りローカルリポジトリの場所を変更してみてください。これはフレームワーク統合であるため、ここでは特定の変更方法については説明しません。ショートカットキーCtrl+Alt+S、次のように検索ボックスでMavenを検索
9. Mavenのコア構成ファイル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.sd"> <modeleversion> 4.0.0 </modelversion> <グループ<バージョン> 1.0-snapshot </version> <packaging> war </packaging> <! - 抽出バージョンプロパティ - > <プロパティ> <spring.version> 4.2.4.release </spring.version> <mybatis.version> 3.2.8 </mybatis.version> <mybatis.spring.spring.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2. <slf4j.version> 1.6.4 </slf4j.version> <log4j.version> 1.2.17 </log4j.version> <jackson.version> 2.4.2 </jackson.version> <druid.version> 1.0.9 </druid.version> <jstl.version> 1.2 </jstl.version> <servlet-api.version> 2.5 </servlet-api.version> <jsp-api.version> 2.0 </jsp-api.version> <commons-io.version> 1.3.2 </commons-io.version> <commons-fileupload.version> 1.3.1 </commons-fileupload.version> </properties> <! - バージョンロック - > <依存関係> <依存関係> < </dependency> <dependency> groupid> org.springframework </groupid> <artifactid> spring-beans </artifactid> <version> $ {spring.version} </bersion> </dependency> <ependency> org.springframework </groupid> spring-webmvcc </artifactid> <バージョン> $ {spring.version} </version> </dependency> <dependency> <groupid> org.springframework </groupid> <artifactid> spring-jdbc </artifactid> <version> $ {spring.version} </version> </despendency> <seplency> <artifactid> spring-aspects </artifactid> <version> $ {spring.version} </version> </dependency> <dependency> <expendency> <groupid> org.springframework </groupid> <artifactid> spring-jms </artifactid> <バージョン> $ {spring.version} <groupid> org.springframework </groupid> <artifactid> spring-context-support </artifactid> <version> $ {spring.version} </version> </dependency> <! - > <依存関係> <groupid> org.mybatis </groupid> <artifactis> artifactid> <バージョン> $ {mybatis.version} </version> </dependency> <dependency> <shipid> org.mybatis </groupid> <artifactid> mybatis-spring </artifactid> <バージョン> $ {mybatis.spring.version} </version> </diestency> <! <GroupId> org.slf4j </groupid> <artifactid> slf4j-log4j12 </artifactid> <version> $ {slf4j.version} </version> </dependency> <dependency> <groupid> log4j </groupid> <artifactid> log4J </artifactid> </$> $> $> $> </Dependency> <! - Jackson JSON Processing Toolkit-> <Dependency> <groupId> com.fasterxml.jackson.core </groupid> <artifactid> $ {jackson.version} </version> </dependency> < <artifactid> druid </artifactid> <version> $ {druid.version} </version> </dependency> <! - mysql - > <dependency> groupid> mysql> <artifactid> mysql-connector-java </artifactid> </</</</</</</</</</</</</</</</</</</</</</</</</</</</</</</パッケージ - > <依存関係> groupid> org.apache.commons </groupid> <artifactid> commons-io </artifactid> <version> $ {commons-io.version} </version} </dependency> <! - ファイルアップロードコンポーネント - > <依存関係> <依存関係> <グループ<バージョン> $ {commons-fileupload.version} </version> </dependency> <! - jsp-related-> <dependency> <groupid> jstl </groupid> <artifactid> jstl </artifactid> <バージョン> $ {jstl.version} </version <artifactid> servlet-api </artifactid> <version> $ {servlet-api.version} </version> <scope> revide </scope> </dependency> <dependency> groupid> javax.servlet </groupid> <artifactid> jsp-api </artifactid> <version> $> $> </version <scope> revide </scope> </dependency> </dependencies> </dependencymanagement> <! - dependencies-> <dependencies> <! - spring-> <dependency> springframework </groupid> <artifactid> spring-context </artifactid> </depenty> <depenty> <depenty> <depenty> <depenty </dependency> <dependency> groupid> org.springframework </groupid> <artifactid> spring-beans </artifactid> </dependency> <expendency> springframework </groupid> <artifactid> spring-webmvc </artifactid <Artifactid> spring-jdbc </artifactid> </dependency> <dependency> <shipid> org.springframework </groupid> <artifactid> spring-aspects </artifactid> </dependency> <依存関係> <groupid> org.spramework < <groupid> org.springframework </groupid> <artifactid> spring-context-support </artifactid> </dependency> <! - mybatis-> <依存関係> groupid> org.mybatis </groupId> <artifactid> mybatis </artifactid> </depenting> <deprigency> <despenty> <artifactid> mybatis-spring </artifactid> </dependency> <! - log processing-> <依存関係> groupid> org.mybatis </groupid> <artifactid> mybatis-spring </artifactid> </dependency> < <artifactid> slf4j-log4j12 </artifactid> </dependency> <! - jackson json processing toolkit-> <dependency> <groupid> com.fasterxml.jackson.core </groupid> <artifactid> Jackson-Databind </artifactid> <artifactid> druid </artifactid> </dependency> <! - mysql - > <依存関係> groupid> mysql </groupid> <artifactid> mysql-connector-java </artifactid> <artifactid> commons-io </artifactid> </dependency> <! - ファイルアップロードコンポーネント - > <依存関係> groupid> commons-fileupload> commons-fileupload </artifactid> </dependency> < <artifactid> jstl </artifactid> </dependency> <dependency> <shipid> javax.servlet </groupid> <artifactid> servet-api </artifactid> <scope> <scope> revide </scope> </dependency> </dependency> <burtion> <! - javaコンピレーションプラグイン - > <プラグイン> <プラグイン><groupId> org.apache.maven.plugins </groupid> <artifactins> maven-compiler-plugin </artifactid> <ターゲット> 1.8 </ターゲット> <エンコード> UTF-8 </encoding> </configuration> </plugin> </plaginins> <! - 構成リソースファイルマッピング - > <リソース> <リソース> <リソース> <ディレクトリ> java </ディレクトリ> <含まれる> <cludent> **/*。 <Directory> src/main/resources </directory> <cludence> <cludence> **/*。プロパティ</include> <cond> **/*。xml </incturing> </incruction> <filtering> false </filtering> </resource> </resources> </build> </project>10.リソースディレクトリに構成ファイルを追加します
ファイルディレクトリは次のとおりです
a)データベース構成情報ファイル-DB.Propertiesに接続します
druid.driver = com.mysql.jdbc.driver druid.url = jdbc:mysql:// localhost:3306/all_db?charaterencoding = utf-8 druid.username = root druid.password = root
b)mybatisコア構成ファイル-SQLMAPCONFIG.XML
<?xml version = "1.0" encoding = "utf-8"?> <!doctype構成public " - // mybatis.org//dtd config 3.0 // en" "http://mybatis.org/dtd/mybatis-3-config.dtd" name = "com.xiao.pojo"/> </typealiase> </configuration>
c)Spring Core構成ファイル、MyBatis、ApplicationContext.xmlの統合
<?xml version = "1.0" encoding = "utf-8"?> <beans xmlns:xsi = "http://www.w3.org/2001/xmlschema-instance" xmlns = "http://www.springframework.org/schema/beans" xmlns:Context = "http://www.springframework.org/schema/context" xmlns:tx = "http://www.springframework.org/schema/tx" xsi:schemalocation = "http://ww.springframework http://www.springframework.org/schema/beans/spring-beans-4.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context-4.pring-context-4 http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.2.xsd "> <! - データベース接続情報構成のロードプール - > <bean id = "dataSource"> <プロパティ名= "driverclassname" value = "$ {druid.driver}" /> <プロパティ名= "url" value = "$ {druid.url}" /> <プロパティ名= "username" value = "$ {druid.username} /> < /bean> <! - mybatis工場の構成 - > <bean id = "sqlsessionfactory"> <プロパティ名= "dataSource" ref = "datasource" /> <プロパティ名 "値=" classpath:sqlmapconfig.xml " />> < /bean naved evelopment package a beand a a beand a a beand a beanインターフェイスの実装クラスを作成するのに同じである - > <bean> <プロパティ名= "basepackage" value = "com.xiao.mapper" /> < /bean> <! - ターンオンシングス - > <bean id = "transactionmanager"> <プロパティ名= "dataSource" ref = "ref =" datasource " </豆> d)SpringMVC構成ファイル-SpringMvc.xml
<?xml version = "1.0" encoding = "utf-8"?> <beans xmlns:xsi = "http://www.w3.org/2001/xmlschema-instance" xmlns = "http://www.springframework.org/schema/beans" xmlns:Context = "http://www.springframework.org/schema/context" xmlns:mvc = "http://www.springframework.org/schema/mvc" xsi:schemalocation = " http://www.springframework.org/schema/beans/spring-beans-4.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context-4.pring-context-4 http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/ @Controller @Service --> <context:component-scan base-package="com.xiao" /> <!-- SpringMVC automatically loads RequestMappingHandlerMapping and RequestMappingHandlerAdapter using <mvc:annotation-driven> --> <mvc:annotation-driven /> <!-- Configure static resource mapping --> <!-- <mvc:resources location="/js/" mapping = "/js/**"/> <mvc:resources location = "/css/" mapping = "/css/**"/> <mvc:resources location = "/font/" mapping = "/font/**"/> - > < value = "/web-inf/jsp/"/> <! - 論理ビュー用の接尾辞を構成 - > <プロパティ名= "suffix" value = "/> </bean> </beans>
11。Web.xmlファイルを構成します
<?xml version = "1.0" encoding = "utf-8"?> <web-app xmlns = "http://java.sun.com/xml/ns/javaee" xmlns:xsi = "http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation = "http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"バージョン= "2.5"> <ディスプレイ名> </welcome-file-list> <! - springリスナー - > <リスナー> <リスナークラス> org.springframework.web.context.contextloaderlistener </ristener-class> </ristener> <! - スプリングコア構成ファイルを指定 - > <context-param> <param-lame> <param-value> classpath:applicationContext.xml </param-value> </context-param> <! - ハンドル投稿送信の文字化け問題 - > <filter> <filter-name>エンコード</filter-name> <filter-class> org.springframework.web.filter.filter.characterencodingfilter <param-value> utf-8 </param-value> </init-param> </filter> <filter-mapping> <filter-name>エンコード</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <! <Servlet-Class> org.springframework.web.servlet.dispatcherservlet </servlet-class> <! - 構成ファイルの場所と名前を指定します。設定されていない場合、デフォルトは/web-inf/< servlet-name>-servlet.xmlを見つけることです。 <Servlet-Name> springMVC </servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> </web-app>
12。ディレクトリ構造を改善し、エンティティクラス、Webレイヤー、サービスレイヤー、DAOレイヤー、テストページを書き込み、ディレクトリ構造は次のとおりです。
13。Tomcatを構成します
14。Tomcatを開始、アクセスアドレス:http:// localhost:8080/getall for Testing、結果は次のとおりです。
上記の結果が表示され、SSMフレームワークが正常に構築されていることを示しています!
データベースデータは次のとおりです
EL式を使用して、JSPページで値を取得します
要約します
上記は、編集者によって紹介されたSSMフレームワークを構築するためにIntellijのアイデアを使用するためのグラフィックチュートリアルです。私はそれが誰にでも役立つことを願っています。ご質問がある場合は、メッセージを残してください。編集者は、すべての人に時間内に返信します。 wulin.comのウェブサイトへのご支援ありがとうございます!