From 9f3535c803192230fcb7bda48a481990f7f92f06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E4=B9=89?= Date: Sun, 14 Oct 2018 23:40:16 +0800 Subject: [PATCH] Initial commit --- custom-framework.iml | 15 ++++ framework/framework.iml | 30 ++++++++ framework/pom.xml | 76 +++++++++++++++++++ .../custom/framework/constants/Constants.java | 19 +++++ .../custom/framework/helper/ConfigHelper.java | 72 ++++++++++++++++++ .../com/custom/framework/util/PropsUtil.java | 31 ++++++++ pom.xml | 17 +++++ test/pom.xml | 36 +++++++++ test/src/main/java/com/custom/test/Test.java | 22 ++++++ test/src/main/resources/framework.properties | 10 +++ test/test.iml | 30 ++++++++ 11 files changed, 358 insertions(+) create mode 100644 custom-framework.iml create mode 100644 framework/framework.iml create mode 100644 framework/pom.xml create mode 100644 framework/src/main/java/com/custom/framework/constants/Constants.java create mode 100644 framework/src/main/java/com/custom/framework/helper/ConfigHelper.java create mode 100644 framework/src/main/java/com/custom/framework/util/PropsUtil.java create mode 100644 pom.xml create mode 100644 test/pom.xml create mode 100644 test/src/main/java/com/custom/test/Test.java create mode 100644 test/src/main/resources/framework.properties create mode 100644 test/test.iml diff --git a/custom-framework.iml b/custom-framework.iml new file mode 100644 index 0000000..8d8ffd9 --- /dev/null +++ b/custom-framework.iml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/framework/framework.iml b/framework/framework.iml new file mode 100644 index 0000000..a992626 --- /dev/null +++ b/framework/framework.iml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/framework/pom.xml b/framework/pom.xml new file mode 100644 index 0000000..337d6ac --- /dev/null +++ b/framework/pom.xml @@ -0,0 +1,76 @@ + + + + custom-framework + com.custom.framework + 1.0-SNAPSHOT + + 4.0.0 + + framework + + + + javax.servlet + javax.servlet-api + 3.1.0 + + + javax.servlet.jsp + jsp-api + 2.2 + provided + + + org.slf4j + slf4j-log4j12 + 1.7.25 + + + mysql + mysql-connector-java + 5.1.33 + runtime + + + com.fasterxml.jackson.core + jackson-databind + 2.4.4 + + + org.apache.commons + commons-lang3 + 3.3.2 + + + org.apache.commons + commons-collections4 + 4.0 + + + commons-dbutils + commons-dbutils + 1.6 + + + org.apache.commons + commons-dbcp2 + 2.0.1 + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.3 + + 1.8 + 1.8 + + + + + \ No newline at end of file diff --git a/framework/src/main/java/com/custom/framework/constants/Constants.java b/framework/src/main/java/com/custom/framework/constants/Constants.java new file mode 100644 index 0000000..e6e9446 --- /dev/null +++ b/framework/src/main/java/com/custom/framework/constants/Constants.java @@ -0,0 +1,19 @@ +package com.custom.framework.constants; + +/** + * @author liuyi + * @date 2018/10/14 + */ +public class Constants { + + public static final String CONFIG_FILE = "framework"; + public static final String JDBC_DRIVER ="framework.jdbc.driver"; + public static final String JDBC_URL = "jdbc:mysql://localhost:2206/demo"; + public static final String JDBC_USERNAME = "framework.jdbc.username"; + public static final String JDBC_PASSWORD = "framework.jdbc.password"; + public static final String FRAMEWORK_JDBC_APP_BASE_PACKAGE = "framework.jdbc.app.base_package"; + public static final String FRAMEWORK_JDBC_JSP_PATH = "framework.jdbc.jsp_path"; + public static final String FRAMEWORK_JDBC_ASSET_PATH= "framework.jdbc.asset_path"; + + +} diff --git a/framework/src/main/java/com/custom/framework/helper/ConfigHelper.java b/framework/src/main/java/com/custom/framework/helper/ConfigHelper.java new file mode 100644 index 0000000..a13ce74 --- /dev/null +++ b/framework/src/main/java/com/custom/framework/helper/ConfigHelper.java @@ -0,0 +1,72 @@ +package com.custom.framework.helper; + +import com.custom.framework.constants.Constants; +import com.custom.framework.util.PropsUtil; + +import java.util.ResourceBundle; + +/** + * @author liuyi + * @date 2018/10/14 + */ +public class ConfigHelper { + + private static final ResourceBundle resource = PropsUtil.getResource(Constants.CONFIG_FILE); + + /** + * 获取JDBC驱动 + * @return + */ + public static String getJdbcDriver() { + return PropsUtil.getString(resource, Constants.JDBC_DRIVER); + } + + /** + * 获取JDBC URL + * @return + */ + public static String getJdbcUrl() { + return PropsUtil.getString(resource, Constants.JDBC_URL); + } + + /** + * 获取JDBC 用户名 + * @return + */ + public static String getJdbcUsername() { + return PropsUtil.getString(resource, Constants.JDBC_USERNAME); + } + + /** + * 获取JDBC 密码 + * @return + */ + public static String getJdbcPassword() { + return PropsUtil.getString(resource, Constants.JDBC_PASSWORD); + } + + /** + * 获取应用基础包名 + * @return + */ + public static String getAppBasePackage() { + return PropsUtil.getString(resource, Constants.FRAMEWORK_JDBC_APP_BASE_PACKAGE); + } + + /** + * 获取应用JSP路径 + * @return + */ + public static String getAppJspPath() { + return PropsUtil.getString(resource, Constants.FRAMEWORK_JDBC_JSP_PATH); + } + + /** + * 获取应用静态资源文件路径 + * @return + */ + public static String getAppAssetPath() { + return PropsUtil.getString(resource, Constants.FRAMEWORK_JDBC_ASSET_PATH); + } + +} diff --git a/framework/src/main/java/com/custom/framework/util/PropsUtil.java b/framework/src/main/java/com/custom/framework/util/PropsUtil.java new file mode 100644 index 0000000..726f732 --- /dev/null +++ b/framework/src/main/java/com/custom/framework/util/PropsUtil.java @@ -0,0 +1,31 @@ +package com.custom.framework.util; + +import java.util.ResourceBundle; + +/** + * @author liuyi + * @date 2018/10/14 + */ +public class PropsUtil { + + /** + * 根据属性文件获取资源 + * @param name + * @return + */ + public static ResourceBundle getResource(String name) { + ResourceBundle resource = ResourceBundle.getBundle(name); + return resource; + } + + /** + * 根据key获取value + * @param resourceBundle + * @param key + * @return + */ + public static String getString(ResourceBundle resourceBundle, String key) { + return resourceBundle.getString(key); + } + +} diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..db90994 --- /dev/null +++ b/pom.xml @@ -0,0 +1,17 @@ + + + 4.0.0 + + com.custom.framework + custom-framework + pom + 1.0-SNAPSHOT + + framework + test + + + + \ No newline at end of file diff --git a/test/pom.xml b/test/pom.xml new file mode 100644 index 0000000..886702e --- /dev/null +++ b/test/pom.xml @@ -0,0 +1,36 @@ + + + + custom-framework + com.custom.framework + 1.0-SNAPSHOT + + 4.0.0 + + test + + + + com.custom.framework + framework + 1.0-SNAPSHOT + + + + + + + org.apache.tomcat.maven + tomcat7-maven-plugin + 2.2 + + ${project.artifactId} + + + + + + + \ No newline at end of file diff --git a/test/src/main/java/com/custom/test/Test.java b/test/src/main/java/com/custom/test/Test.java new file mode 100644 index 0000000..fb6fc44 --- /dev/null +++ b/test/src/main/java/com/custom/test/Test.java @@ -0,0 +1,22 @@ +package com.custom.test; + + +import java.util.ResourceBundle; + +/** + * @author liuyi + * @date 2018/10/14 + */ +public class Test { + + public static void main(String[] args) { + System.out.println(getString("framework", "framework.jdbc.asset_path")); + } + public static ResourceBundle getResource(String name) { + ResourceBundle resource = ResourceBundle.getBundle(name); + return resource; + } + public static String getString(String name, String key) { + return getResource(name).getString(key); + } +} diff --git a/test/src/main/resources/framework.properties b/test/src/main/resources/framework.properties new file mode 100644 index 0000000..df51c06 --- /dev/null +++ b/test/src/main/resources/framework.properties @@ -0,0 +1,10 @@ +framework.jdbc.driver=com.mysql.jdbc.Driver +framework.jdbc.url=jdbc:mysql://localhost:2206/demo +framework.jdbc.username=root +framework.jdbc.password=root +#\u9879\u76EE\u5305\u540D +framework.jdbc.app.base_package=com.custom.framework.test +#jsp\u7684\u57FA\u7840\u8DEF\u5F84 +framework.jdbc.jsp_path=/WEB-INF/view/ +#\u9759\u6001\u8D44\u6E90\u6587\u4EF6\u7684\u57FA\u7840\u8DEF\u5F84 +framework.jdbc.asset_path=/asset/ diff --git a/test/test.iml b/test/test.iml new file mode 100644 index 0000000..ac119a9 --- /dev/null +++ b/test/test.iml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file