スプリングのcontext.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" 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 /スキーマ/コンテキスト/春-context.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd "> <コンテキスト:アノテーションのconfig /> <コンテキスト:コンポーネント・スキャンベースパッケージ=「com.funtl.my.shop.web.admin」> <コンテキスト:除外フィルタのタイプ=「注釈」表現=「org.springframework.stereotype.Controller」/> </コンテキスト:コンポーネント・スキャン> <! -配置豆バリ定义- > <豆ID = "バリ"クラス= "org.springframework.validation.beanvalidation.LocalValidatorFactoryBean" /> <豆のid = "beanValidator"クラス= "com.funtl.my.shop.commons.validator.BeanValidator"> <プロパティ名= "バリ" REF = "バリ" /> </豆> <! -配置事务管理器- > <豆ID =」トランザクションマネージャー"クラス= "org.springframework.jdbc.datasource.DataSourceTransactionManager"> <プロパティ名= "データソース" REF = "データソース"/> </豆> <! -注釈駆動型トランザクションを開きます- > <TX:注釈駆動型トランザクション・マネージャ= "のTransactionManager" /> </豆>
BeanValidatorツール
org.springframework.beans.factory.annotation.Autowiredインポート、 インポートjavax.validation.ConstraintViolation; インポートjavax.validation.ConstraintViolationException; インポートjavax.validation.Validator; java.util.ArrayListののインポート、 インポートのjava.util.HashMap; Javaソースコードの読み込み.util.List; インポートjava.util.Map; インポートjava.util.Set; / ** * JSR303バリ(バリ休止状態)のツール * <P> * ConstraintViolationはのPropertyPath、メッセージ情報とinvalidValueを含んで *提供国際化のさまざまなニーズのための様々な方法を変換します * 1。リスト<文字列>、メッセージへの文字列の内容 * 2.一覧<文字列>、メッセージのPropertyPathへのコンテンツのStringセパレータ+ + * 3.地図<のPropertyPath、メッセージ> * <P> *詳細については、ウィキ:https://github.com/springside/springside4/wiki/HibernateValidator * * <P>タイトル:BeanValidator </ P> * <P>説明:</ P> * * @author Lusifer * @version 1.0.0 * @date 2018年6月26日17:21 * / publicクラスBeanValidator { //が自動的に注入することができない@Autowiredは、静的プロパティで注入することはできません、あなたはこのコメント、手動で注入するために、次の必要性を削除することができます プライベート静的検証バリデータを、 公衆ボイドsetValidator静的(バリバリ){ BeanValidator.validator =バリ; } / ** * JSR303コール検証がConstraintViolationExceptionがスロー失敗した場合、メソッドを検証します。 * / プライベートの静的な無効validateWithException(<?>バリバリデータ、Objectオブジェクト、クラス...グループ)ConstraintViolationException {スロー セットconstraintViolations = validator.validate(オブジェクト、グループ)。 (!constraintViolations.isEmpty()){もし 新しいConstraintViolationException(constraintViolations)を投げます。 } } / ** *辅助方法、转换ConstraintViolationException中的セット<ConstraintViolations>中为一覧<メッセージ>。 * / プライベート静的リスト<文字列> extractMessage(ConstraintViolationException e)は{ ()(e.getConstraintViolations)extractMessageを返します。 } / ** *辅助方法、转换セット<ConstraintViolation>为一覧<メッセージ> * / プライベート静的リスト<文字列> extractMessage {(設定constraintViolations <ConstraintViolationを拡張する?>) 一覧<文字列> errorMessages =新しいArrayListを<>(); (ConstraintViolation違反:constraintViolations)用{ errorMessages.add(violation.getMessage())。 } errorMessagesを返します。 } / ** *辅助方法、转换ConstraintViolationException中的セット<ConstraintViolations>地図<プロパティ、メッセージ>为。 * / プライベート静的地図<文字列、文字列> extractPropertyAndMessage(ConstraintViolationException電子){ extractPropertyAndMessage(e.getConstraintViolationsを())を返します。 } / ** *辅助方法、转换セット<ConstraintViolation>地図<プロパティ、メッセージ>为。 * / プライベート静的地図<文字列、文字列> extractPropertyAndMessage {(設定constraintViolations <ConstraintViolationは拡張?>) 地図<文字列、文字列> errorMessages =新しいHashMapの<>(); (ConstraintViolation違反:constraintViolations)用{ errorMessages.put(violation.getPropertyPath()のtoString()、violation.getMessage())。 } errorMessagesを返します。 } / ** *辅助方法、转换ConstraintViolationException中的セット<ConstraintViolations>为一覧<のPropertyPathメッセージ>。 * / プライベート静的リスト<文字列> extractPropertyAndMessageAsList(e.getConstraintViolations()、 "「)を返します。 } / ** *辅助方法、转换セット<ConstraintViolations>为一覧<のPropertyPathメッセージ>。 * / プライベート静的リスト<文字列> extractPropertyAndMessageAsList(設定constraintViolations <ConstraintViolationを拡張する?>){ extractPropertyAndMessageAsList(constraintViolationsを、 "「)を返します。 } / ** *辅助方法、转换ConstraintViolationException中的セット<ConstraintViolations>リストの<のPropertyPath +セパレータ+メッセージ>为。 * / プライベート静的リストの<string> extractPropertyAndMessageAsList(ConstraintViolationException電子、文字列の区切り){ extractPropertyAndMessageAsList(e.getConstraintViolations()、セパレータ)を返します。 } / ** *辅助方法、转换セット<ConstraintViolation>リスト为<のPropertyPath +セパレータ+メッセージ>。 * / プライベート静的リスト<文字列> extractPropertyAndMessageAsList(セットconstraintViolations、文字列の区切り<ConstraintViolationを拡張?>){ リストの<string> errorMessages =新規のArrayList <>(); (ConstraintViolation違反:constraintViolations)用{ errorMessages.add(violation.getPropertyPath()+セパレータ+ violation.getMessage())。 } errorMessagesを返します。 } / ** *服务端参数有效性验证 * * @Paramオブジェクト検証エンティティ・オブジェクト * @paramグループの検証グループ * @return成功を確認してください。リターンはnullを、検証が失敗しました:返すエラーメッセージ * / パブリック静的文字列の検証(<?>オブジェクトオブジェクト、クラス...グループ){ 試み{ validateWithException(バリデータ、オブジェクト、グループ); }キャッチ(ConstraintViolationException EX){ リストの<string>一覧= extractMessage(EX); List.add(0は、 "データ検証に失敗しました:"); //エラーメッセージは、文字列パッケージであります StringBuilderの新しい新しいSBはStringBuilderの()=; {(私は++;;私ははlist.size()<I = 0をint型)のための 文字列ExMSG = List.get(I)を、 IF(I = 0!){ sb.append(String.Formatの( "%sの%sの。"、I、exMsg))追加(はlist.size()> 1 "<BR/>"? "")。 }他{ sb.append(exMsg).append(?はlist.size()> 1 "<BR/>": "")。 } } )(sb.toStringを返します。 } はnullを返します。 } }
春-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:MVC = "http://www.springframework.org/schema/mvc" XSI:のschemaLocation =" http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/contextのhttp:// WWW .springframework.org /スキーマ/コンテキスト/スプリングcontext.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd "> <記述> Spring MVCの設定</説明> <! -コンフィギュレーションのプロパティファイルをロード- > <コンテキスト:無視-解決できないプロパティ・プレースホルダー= "trueに" LOCATION = "CLASSPATH:myshop.properties" /> <! -自動登録豆を使用して注釈、唯一@Controllerスキャン- > <コンテキスト:スキャンのコンポーネント・ベース・パッケージ変更を「偽の」=「com.funtl.my.shop.web.admin」使用デフォルト・フィルタ=> <文脈:含めるフィルタ型=「注釈」=表現「org.springframework.stereotype.Controller」/> </コンテキスト:コンポーネントスキャン> < -デフォルトのマッピング・アノテーションをサポートしています- >! <MVC:注釈ドリブン/> <! -ビューのファイルの解析の定義- > <beanクラス=「org.springframework.web.servlet .view.InternalResourceViewResolver "> <プロパティ名="接頭辞"値=" $ {web.view。プレフィックス} "/> <プロパティ名="サフィックス」値= "$ {web.view.suffix}" /> </豆> <! -静态资源映射- > :<MVCリソースマッピング= "/静的/ **"の場所= "/静的/"キャッシュ期間= "31536000" /> <! -拦截器配置- > < MVC:インターセプタ> <MVC:インターセプター> <MVC:マッピングパス= "/ **" /> <MVC:除外マッピングパス= "/ログイン" /> <MVC:静的除外マッピングパス= "/ / ** "/> <beanクラス=" com.funtl.my.shop.web.admin.web.interceptor.LoginInterceptor」/> </ MVC:インターセプター> <MVC:インターセプター> <MVC:マッピング・パス= "/ **" /> <= "com.funtl.my.shop.web.admin.web Beanクラス。interceptor.PermissionInterceptor」/> </ MVC:迎撃> </ MVC:インターセプタ> <! -傍受するファイルをアップロードし、設定された最大アップロードファイルサイズ= 10 * 1024 * 10M 1024(B)= 10485760バイト- > 上記のid = "MultipartResolver"クラス=「org.springframework.web.multipart.commons.CommonsMultipartResolverを言及したの<bean "> <プロパティ名=" maxUploadSize "値=" $ {web.maxUploadSize}「/> </ビーン> </豆>
MyBatisの-config.xmlの
<?xmlのバージョン= "1.0"エンコード= "UTF-8"?> <構成PUBLICをDOCTYPE! " - // mybatis.org//DTDコンフィグ3.0 // EN"「http://mybatis.org/dtd/mybatis config.dtd - 3 "> <構成> <! -グローバルパラメータ- > <設定> <! - SQL文を印刷する- > <設定名=" logImpl "値=" STDOUT_LOGGING「/> <! - -キャッシュを有効または無効にするグローバルマップ。- > <設定名= "cacheEnabled"値= "偽" /> <! -世界的には、遅延ロードを有効または無効にします。無効にすると、すべての関連付けを熱心にロードされます。- > <設定名=「lazyLoadingEnabled」値=「trueに」/> <! -有効にすると、任意のプロパティが呼び出されたときにオブジェクトのプロパティを読み込み遅延が完全にロードされますがあります。そうでない場合は、各プロパティには、オンデマンドでロードされます。- > </ "trueに"名前= "multipleResultSetsEnabled"値を=設定> <! -エイリアス(ドライブの互換性に依存する)ことができますデフォルトの列:trueに- > <設定名= "useColumnLabel"値= "trueに" /> <! - JDBCは、主キーを生成することができます。あなたはサポートを駆動する必要があります。trueに設定されている場合、この設定は、主キーを生成するために使用するように強制されます、いくつかのドライバがあります互換性がありませんが、それでも実行することができます。デフォルト:falseに- > <設定名=「useGeneratedKeys」値=「falseに」/> <は-自動的に列をマップする方法を指定NONEは、データベーステーブルをMyBatisのない:! PARTIALをマップしない:パートFULL:すべての- > <設定名を=「autoMappingBehavior」値=「PARTIAL」/> < -これはデフォルトの実行タイプがある!(シンプル:シンプル; REUSE:アクチュエータは、プリペアドステートメントのステートメントを再利用することができ、バッチ:文とバッチ更新を繰り返すことができ、アクチュエータ) - - > <設定名= "defaultExecutorType"値= " <設定名=「mapUnderscoreToCamelCase」値=「trueに」/> < -ローカルキャッシュの範囲セッションを設定:!データは、ステートメントを共有します:文の範囲(これは共有データを持っていません)defalut:セッション- > <設定名=「localCacheScope」値=「SESSION」/> < - - JDBCタイプを設定するが空で、指定した値にいくつかのドライバは、デフォルト:!他、挿入がヌルのタイプを指定する必要はありません> <設定=名前"jdbcTypeForNull"値= "NULL" /> </設定> </構成>
春・コンテキストmybatis.xml
<?XMLバージョン= "1.0"エンコード= "UTF-8"> <ビーンズのxmlns = "http://www.springframework.org/schema/beans"のxmlns:XSI =「http://www.w3.org / 2001 / XMLスキーマ・インスタンス" のxsi:schemaLocationの=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd HTTP:// WWW。 http://www.springframework.org/schema/tx/spring-tx.xsd springframework.org/schema/tx "> <! - SQLSESSIONを設定- > <豆ID =" SqlSessionFactory "クラス=" org.mybatis .spring.SqlSessionFactoryBean「> <プロパティ名=」データソース「REF =」データソース「/> <! -パッケージは、パッケージの複数の間で使用可能な構成に対応するエンティティクラス『』分割数について- > <プロパティ名= "typeAliasesPackage「値=」com.funtl.my.shop.domain「/> <! -オブジェクト・リレーショナル・マッピング構成ファイルのディレクトリを設定するための- > <プロパティ名= "mapperLocations"値= "クラスパス:/マッパー/ ** / * xmlの。" /> <プロパティ名= "configLocation"値= "クラスパス:/mybatis-config.xml"> </ property>の </豆> <! -扫描マッパー- > <beanクラス= "org.mybatis.spring.mapper.MapperScannerConfigurer"> <プロパティ名= "basePackage"値= "com.funtl.my.shop.web.admin.dao "/> </豆> </豆>
log4j.properties
log4j.rootLogger = DEBUG、コンソール、ファイル log4j.appender.console = org.apache.log4j.ConsoleAppender log4j.appender.console.layout = org.apache.log4j.PatternLayout log4j.appender.console.layout.ConversionPattern =%D% P [%のC] - %のM%N log4j.appender.file = org.apache.log4j.DailyRollingFileAppender log4j.appender.file.File = D://logs/log.log log4j.appender.file.layout = ORG。 apache.log4j.PatternLayout log4j.appender.A3.MaxFileSize = 1024キロバイト log4j.appender.A3.MaxBackupIndex = 10 log4j.appender.file.layout.ConversionPattern =%d個の%のP [%のC] - %のm個の%nを