Donkey框架之二:工具類模組

百聯達發表於2017-07-11
一:簡介

該模組主要包含自定義註解標籤,自定義異常類,檔案處理工具類,常用工具類和常用VO 等部分組成。




點選(此處)摺疊或開啟

  1. <?xml version="1.0"?>
  2. <project
  3.     xsi:schemaLocation=" "
  4.     xmlns="" xmlns:xsi="">
  5.     <modelVersion>4.0.0</modelVersion>
  6.     <parent>
  7.         <groupId>com.brilliantstar</groupId>
  8.         <artifactId>donkey</artifactId>
  9.         <version>0.0.1-SNAPSHOT</version>
  10.     </parent>

  11.     <groupId>com.brilliantstar</groupId>
  12.     <artifactId>donkey-common-utils-support</artifactId>
  13.     <version>0.0.1-SNAPSHOT</version>
  14.     <name>donkey-common-utils-support</name>
  15.     
  16.         <properties>
  17.         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  18.     </properties>

  19.     <repositories>
  20.         <repository>
  21.             <id>nexus</id>
  22.             <name>BrilliantStar Nexus Repository</name>
  23.             <url>http://121.42.157.168:8081/nexus/content/groups/public</url>
  24.         </repository>
  25.     </repositories>


  26.     <dependencies>

  27.         <dependency>
  28.             <groupId>org.springframework</groupId>
  29.             <artifactId>spring-core</artifactId>
  30.         </dependency>

  31.         <dependency>
  32.             <groupId>org.springframework</groupId>
  33.             <artifactId>spring-beans</artifactId>
  34.         </dependency>

  35.         <dependency>
  36.                 <groupId>org.apache.logging.log4j</groupId>
  37.                 <artifactId>log4j-api</artifactId>
  38.             
  39.             </dependency>
  40.             <dependency>
  41.                 <groupId>org.apache.logging.log4j</groupId>
  42.                 <artifactId>log4j-core</artifactId>
  43.                 
  44.             </dependency>
  45.             
  46.             <dependency>
  47.                 <groupId>org.apache.logging.log4j</groupId>
  48.                 <artifactId>log4j-slf4j-impl</artifactId>
  49.             </dependency>

  50.     <dependency>
  51.         <groupId>org.apache.logging.log4j</groupId>
  52.         <artifactId>log4j-web</artifactId>
  53.     </dependency>

  54.         <dependency>
  55.             <groupId>com.google.code.gson</groupId>
  56.             <artifactId>gson</artifactId>
  57.         </dependency>

  58.         <dependency>
  59.             <groupId>org.apache.commons</groupId>
  60.             <artifactId>commons-lang3</artifactId>
  61.         </dependency>

  62.         <dependency>
  63.             <groupId>commons-io</groupId>
  64.             <artifactId>commons-io</artifactId>
  65.         </dependency>

  66.         <dependency>
  67.             <groupId>com.fasterxml.jackson.core</groupId>
  68.             <artifactId>jackson-databind</artifactId>
  69.         </dependency>

  70.         <dependency>
  71.             <groupId>org.apache.poi</groupId>
  72.             <artifactId>poi</artifactId>
  73.         </dependency>

  74.         <dependency>
  75.             <groupId>net.sf.json-lib</groupId>
  76.             <artifactId>json-lib</artifactId>
  77.             <classifier>jdk15</classifier>
  78.         </dependency>
  79.         
  80.             <dependency>
  81.                 <groupId>bouncycastle</groupId>
  82.                 <artifactId>bcprov-jdk15</artifactId>
  83.             </dependency>
  84.         
  85.     </dependencies>
  86. </project>



二:註解模組

註解模組主要自定義了針對請求和返回結果進行統一處理的標籤; 如含有 @DonkeyEncryptRequest 標籤,則表示會對請求引數進行3DES解密;@DonkeyEnhanceEncryptRequest 對請求引數進行RSA解密。  而@DonkeyEncryptResponse 表示對返回結果進行3DES加密。



 @DonkeyEncryptRequest 標籤程式碼示例

點選(此處)摺疊或開啟

  1. @Target(ElementType.PARAMETER)
  2. @Retention(RetentionPolicy.RUNTIME)
  3. @Documented
  4. public @interface DonkeyEncryptRequest {
  5. }

 @DonkeyEncryptRequest 標籤使用程式碼示例


點選(此處)摺疊或開啟

  1. /**
  2.      * @description 活動報名使用者列表查詢
  3.      * @param
  4.      * @return ReturnBody
  5.      * @throws
  6.      */
  7.     @ResponseBody
  8.     @RequestMapping(value = "/activityEnrollList", method = RequestMethod.POST)
  9.     public ReturnBody activityEnrollList(
  10.             @EncryptRequest RequestObject<ParameterInfo> reqObj) {
  11.         ReturnBody result = new ReturnBody();
  12.         try {
  13.             if (!reqObj.isSuccess()) {
  14.                 return setFailBody(reqObj);
  15.             }
  16.             ParameterInfo param = reqObj.getRequestData();
  17.             String userId = reqObj.getRequestHead().get(
  18.                     Constants.REQUEST_USERID);

  19.             if (0 == param.getActivityId() || StringUtils.isEmpty(userId)) {
  20.                 result.setFail();
  21.                 result.setDesc("必要引數不能為空");
  22.                 return result;
  23.             }
  24.             result.setResult(ghomeActivityEnrollBo
  25.                     .findActivityEnrollList(param));
  26.             result.setSuccess();
  27.             return result;
  28.         } catch (Exception e) {
  29.             logger.error(null, e);
  30.             result.setFail();
  31.             result.setDesc(e.getMessage());
  32.             return result;
  33.         }
  34.     }



三:異常處理模組

所有異常封裝到四類自定義的異常裡面。 



四:檔案處理工具類

主要是各類檔案生成的工具類



五:常用工具類

各種常用工具類



六:常用VO(Value Object)類





來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/28624388/viewspace-2141911/,如需轉載,請註明出處,否則將追究法律責任。

相關文章