From d46b901177c2dacef51d9767792f97b378bf472d Mon Sep 17 00:00:00 2001 From: lzh984294471 <984294471@qq.com> Date: Wed, 15 Jun 2016 09:00:06 +0800 Subject: [PATCH] modified: src/main/java/com/thinker/main/util/BaseProperty.java new file: src/main/resources/jdbc.properties modified: src/test/java/com/thinker/main/util/BaseTest.java --- .../com/thinker/main/util/BaseProperty.java | 30 +++++++++---------- src/main/resources/jdbc.properties | 0 .../java/com/thinker/main/util/BaseTest.java | 2 +- 3 files changed, 16 insertions(+), 16 deletions(-) create mode 100644 src/main/resources/jdbc.properties diff --git a/src/main/java/com/thinker/main/util/BaseProperty.java b/src/main/java/com/thinker/main/util/BaseProperty.java index 410b866..10ae140 100644 --- a/src/main/java/com/thinker/main/util/BaseProperty.java +++ b/src/main/java/com/thinker/main/util/BaseProperty.java @@ -2,12 +2,12 @@ package com.thinker.main.util; import org.apache.log4j.Logger; -import java.io.IOException; -import java.io.InputStream; +import java.io.*; import java.util.Properties; /** * Created by lzh on 16-6-13. + * 用于加载配置文件 */ public class BaseProperty { private static Properties prop; @@ -15,8 +15,15 @@ public class BaseProperty { private static Logger log = Logger.getLogger(BaseProperty.class); static { prop = new Properties(); - log.info("加载配置文件"); - in = BaseProperty.class.getResourceAsStream(BaseProperty.class.getResource("/").getPath()+"/mybatis.properties"); +// log.info("加载配置文件"); + try { + in = new BufferedInputStream(new FileInputStream( + BaseProperty.class.getResource("/").getPath()+"/mybatis.properties")); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } +// in = BaseProperty.class.getResourceAsStream("/mybatis.properties"); + System.out.println(BaseProperty.class.getResource("/").getPath()+"/mybatis.properties"); try { prop.load(in); } catch (IOException e) { @@ -29,17 +36,10 @@ public class BaseProperty { } } } - - public static String getMapping(){ - return prop.getProperty("mapping").trim(); + public static String getValue(String name){ + return prop.getProperty(name); } - - public static String getMapper(){ - return prop.getProperty("mapper").trim(); + public static void main(String[] args) { + System.out.println(BaseProperty.getValue("mapper")); } - -// public static void main(String[] args) { -// System.out.println(BaseProperty.getMapper()); -// } - } diff --git a/src/main/resources/jdbc.properties b/src/main/resources/jdbc.properties new file mode 100644 index 0000000..e69de29 diff --git a/src/test/java/com/thinker/main/util/BaseTest.java b/src/test/java/com/thinker/main/util/BaseTest.java index 8db5cf4..482b83c 100644 --- a/src/test/java/com/thinker/main/util/BaseTest.java +++ b/src/test/java/com/thinker/main/util/BaseTest.java @@ -5,6 +5,6 @@ package com.thinker.main.util; */ public class BaseTest { public static void main(String[] args) { - System.out.println(BaseProperty.getMapper()); + System.out.println(BaseProperty.getValue("mapper")); } }