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 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());
// }
}

View File

View File

@ -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"));
}
}