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
This commit is contained in:
lzh984294471 2016-06-15 09:00:06 +08:00
parent 2e17016f8e
commit d46b901177
3 changed files with 16 additions and 16 deletions

View File

@ -2,12 +2,12 @@ package com.thinker.main.util;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import java.io.IOException; import java.io.*;
import java.io.InputStream;
import java.util.Properties; import java.util.Properties;
/** /**
* Created by lzh on 16-6-13. * Created by lzh on 16-6-13.
* 用于加载配置文件
*/ */
public class BaseProperty { public class BaseProperty {
private static Properties prop; private static Properties prop;
@ -15,8 +15,15 @@ public class BaseProperty {
private static Logger log = Logger.getLogger(BaseProperty.class); private static Logger log = Logger.getLogger(BaseProperty.class);
static { static {
prop = new Properties(); prop = new Properties();
log.info("加载配置文件"); // log.info("加载配置文件");
in = BaseProperty.class.getResourceAsStream(BaseProperty.class.getResource("/").getPath()+"/mybatis.properties"); 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 { try {
prop.load(in); prop.load(in);
} catch (IOException e) { } catch (IOException e) {
@ -29,17 +36,10 @@ public class BaseProperty {
} }
} }
} }
public static String getValue(String name){
public static String getMapping(){ return prop.getProperty(name);
return prop.getProperty("mapping").trim();
} }
public static void main(String[] args) {
public static String getMapper(){ System.out.println(BaseProperty.getValue("mapper"));
return prop.getProperty("mapper").trim();
} }
// public static void main(String[] args) {
// System.out.println(BaseProperty.getMapper());
// }
} }

View File

View File

@ -5,6 +5,6 @@ package com.thinker.main.util;
*/ */
public class BaseTest { public class BaseTest {
public static void main(String[] args) { public static void main(String[] args) {
System.out.println(BaseProperty.getMapper()); System.out.println(BaseProperty.getValue("mapper"));
} }
} }