pom.xml配置
<! - https://mvnrepository.com/artifact/org.springframework/spring-webmvc - > <依存> <groupIdを> org.springframework </ groupIdを> <たartifactId>春-webmvc </たartifactId > <バージョン> 4.3.18.RELEASE </バージョン> </依存関係> <! - https://mvnrepository.com/artifact/org.springframework/spring-jdbc - > <依存> <groupIdを> org.springframework </ groupIdを> <たartifactId>春-JDBC </たartifactId> <バージョン> 4.3.18.RELEASE </バージョン> </依存関係> <! - https://mvnrepository.com/artifact/mysql/mysql-connector- Javaの- > <依存> <groupId> mysqlの</ groupIdを> <たartifactId>のmysql-コネクタ-javaの</たartifactId> <バージョン> 5.1.6 </バージョン> </依存関係> <! - https://mvnrepository.com/artifact/jstl/jstl - > <依存> <groupIdを> JSTL </ groupIdを> <たartifactId> JSTL </たartifactId> <バージョン> 1.2 </ version>の </依存関係> <! - https://mvnrepository.com/artifact/org.mybatis/mybatis - > <依存> <groupIdを> org.mybatis </ groupIdを> <たartifactId> MyBatisの</たartifactId> <バージョン> 3.4.6 </バージョン> </依存関係> <! - https://mvnrepository.com/artifact/org.mybatis/mybatis-spring - > <依存> <groupIdを> org.mybatis </ groupIdを> <たartifactId> mybatis-春</たartifactId> <バージョン> 1.3.2 </バージョン> </依存> <! - https://mvnrepository.com/artifact/com.mchange/c3p0 - > <依存> <groupIdを> com.mchange </ groupIdを> <たartifactId> C3P0 </たartifactId> <バージョン> 0.9.5.2 < /バージョン> </依存関係> <! - https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 - > <依存> <groupIdを> org.apache.commons </ groupIdを> <たartifactId >コモンズ-lang3 </たartifactId> <バージョン> 3.4 </ version>の </依存関係> <! - https://mvnrepository.com/artifact/ch.qos.logback/logback-classic - > <依存> < groupId> ch.qos.logback </ groupIdを> <たartifactId> logback-古典</たartifactId> <バージョン> 1.2.3 </バージョン> </依存関係> <! - https://mvnrepository.com/artifact/ch.qos.logback/logback-core - > <依存> <groupIdを> ch.qos.logback </ groupIdを> <たartifactId> logback-コア</たartifactId > <バージョン> 1.2.3 </バージョン> </依存関係> <! - https://mvnrepository.com/artifact/org.slf4j/slf4j-api - > <依存> <groupIdを> org.slf4j </ groupId> <たartifactId> SLF4J-API </たartifactId> <バージョン> 1.7.26 </バージョン> </依存関係> <! - https://mvnrepository.com/artifact/com.alibaba/fastjson - > <依存関係> <groupIdを> com.alibaba </ groupIdを> <たartifactId> fastjson </たartifactId> <バージョン> 1.2.47 </バージョン> </依存関係>
web.xmlの
<?xml version = "1.0"エンコード= "UTF-8"?> の<web-appののxmlns:XSI = "http://www.w3.org/2001/XMLSchema-instance"のxmlns = "のhttp:// javaのsun.comの/ XML / NS / JavaEEの"XSI:のschemaLocation =" http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0 .xsd」ID = "WebApp_ID"バージョン= "3.0"> <表示名> kuacoo </表示名> <歓迎-ファイル・リスト> <歓迎-ファイル> index.jspを</歓迎ファイル> </歓迎-file-リスト> <! -春和MyBatisの的配置文件- > <コンテキスト-param>の の<param-name>のcontextConfigLocation </ PARAM名> の<param-value>のクラスパス:applicationContext.xmlを</ PARAM値> </コンテキスト-param>の <! -エンコーダフィルタ- > <フィルタ> <フィルタ名> EncodingFilter </フィルタ名> <フィルタクラス> org.springframework.web.filter.CharacterEncodingFilter </フィルタリングクラス> <非同期サポート>真</非同期サポート> の<init-param>要素 の<param-name>のエンコーディング</ PARAM名> < PARAM値> UTF-8 </ PARAM値> </ initの-param>の </フィルタ> <のfilter-mapping> <フィルタ名> encodingFilter </フィルタ名> の<url-pattern> / * </ URL -pattern> </のfilter-mapping> <! -春监听器- > <聞き手> <リスナークラス> org.springframework.web.context.ContextLoaderListener </リスナクラス> </リスナー> <! -春のMVCサーブレット- > の<servlet> の<servlet-name>のspringMvc </サーブレット名> の<servlet-class>のorg.springframework.web.servlet.DispatcherServlet </サーブレットクラス> の<init-param>の <PARAM名> contextConfigLocation </ PARAM名> の<param-value>のクラスパス:春mvc.xml </ PARAM値> </ INIT-PARAM> の<load-on-startup> 1 </ロード・オン・スタートアップ> </サーブレット> <のservlet-mapping> の<servlet-name>のspringMvc </サーブレット名> の<url-pattern> *。行う</のurl-pattern> </のservlet-mapping> </ web-app>の
application.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:TX = "http://www.springframework.org/schema/tx" のxmlns:AOP =" http://www.springframework.org/schema/aop " XSI:のschemaLocation =" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans。 XSD http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop。 XSD "> < -开启包扫描、并注册注解- >! <文脈:コンポーネント・スキャンベースパッケージ=" com.kuacoo.shop "/> <文脈:プロパティプレースホルダ位置="クラスパス:jdbc.properties "/> <! -配置C3P0连接池- > <豆ID ="データソース"クラス= "com.mchange.v2.c3p0.ComboPooledDataSource"> <プロパティ名= "driverClass"値=" $ {jdbc.driverClass } "/> <プロパティ名= "jdbcUrlと"値= "$ {jdbc.url}"/> <プロパティ名= "ユーザ"値="$ {jdbc.username}」/> <プロパティ名= "パスワード"値= "$ {jdbc.password}" /> </豆> <! -配置セッション工厂- > の<beanのid = "sqlSessionFactory"クラス= "org.mybatis.spring.SqlSessionFactoryBean"> <プロパティ名= "データソース" REF = "データソース" /> <プロパティ名= "configLocation"値= "クラスパス:MyBatisの-config.xmlの" /> <プロパティ名= "mapperLocations"値= "クラスパス:。com / kuacoo /ショップ/ DAO / * xmlの" /> </豆> <beanクラス= "ORG。 mybatis.spring.mapper.MapperScannerConfigurer "> <プロパティ名=" basePackage "値= "com.kuacoo.shop.dao"/> </ビーン> <ビーンID = "のTransactionManager"クラス=" org.springframework.jdbc.datasource 。DataSourceTransactionManager "> <プロパティ名="データソース」REF = "データソース" /> </豆> <TX:注釈駆動型トランザクション・マネージャ= "のTransactionManager"> </ TX:注釈駆動型> </豆>
春-mvc.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:TX = "http://www.springframework.org/schema/tx" のxmlns:MVC =" http://www.springframework.org/schema/mvc " のxmlns:AOP = "http://www.springframework.org/schema/aop" のxsi:schemaLocationの =" http://www.springframework.org/schema/豆 のhttp:// www.springframework.org/schema/beans/spring-beans.xsd ます。http:// www.springframework.org/schema/context http:// www.springframework.org/schema/context/spring-context.xsd ます。http:// www.springframework.org/schema/tx ます。http:// www.springframework.org/schema/tx/spring-tx。 XSD のhttp:// www.springframework.org/schema/aop ます。http:// www.springframework.org/schema/aop/spring-aop.xsd ます。http:// www.springframework.org/schema/mvc ます。http:// www.springframework.org/schema/mvc/spring-mvc.xsd "> <コンテキスト:コンポーネント・スキャンベース-のパッケージ =" com.kuacoo.shop.controller "/> <MVC:デフォルト-servletハンドラ/> < -启动MVC默认配置- >! <MVC:注釈駆動型> <MVC:message- コンバータが 登録 -defaults = "真の"> <! -配置fastjson - > <豆のクラス = "com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter"> <プロパティ名= "supportedMediaTypes"> <リスト> <値>テキスト/ HTML;のcharset = UTF-8 </値> <値>アプリケーション/ JSON </値> </リスト> </ property>の <プロパティ名=「機能」> <リスト> <値> WriteMapNullValue </値> <値> QuoteFieldNames </ value>の </リスト> </ property>の </ビーン> </ MVC:メッセージ・コンバータ> </ MVC:アノテーション駆動型> <ビーンクラス = "ORG .springframework.web.servlet.view.InternalResourceViewResolver "> <プロパティ名="接頭辞"値= "/ WEB-INF / JSP /"/> <プロパティ名= "サフィックス"値="。JSP」/> </豆> </豆>
jdbc.properties
jdbc.driverClass = はcom.mysql.jdbc.Driver jdbc.url = JDBCます。mysql:// localhostを:?3306 /ショップcharacterEncoding = UTF-8 jdbc.username = ルート jdbc.password = [密码]
MyBatisの-config.xmlの
<?xmlのバージョン= "1.0"エンコード= "UTF-8"?>
<!DOCTYPE設定
PUBLIC " - // mybatis.org//DTDコンフィグ3.0 // EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<設定>
<! -开启驼峰命名规则自动转换- >
<設定>
<設定名= "mapUnderscoreToCamelCase"値= "true"を/>
</設定>
</ configuration>の
logback.xml
<?xml version = "1.0"エンコード= "UTF-8"?> <設定> <アペンダ名= "STDOUT" クラス = "ch.qos.logback.core.ConsoleAppender"> <! - エンコーダが割り当てられているタイプ ch.qos.logback.classic.encoder.PatternLayoutEncoder デフォルト - > <エンコーダ> <パターン>%のD {HH:MM:SS.SSS} [%スレッド]%-5level%ロガー{36} - %のMSGの%nを</パターン> </エンコーダ> </アペンダ> <ルートレベル= "デバッグ"> <アペンダ-REF REF = "STDOUT" /> </ルート> </構成>