File tree Expand file tree Collapse file tree 5 files changed +44
-12
lines changed
main/java/info/xiaomo/gengine Expand file tree Collapse file tree 5 files changed +44
-12
lines changed Original file line number Diff line number Diff line change 77@ Getter
88public enum ConfigSuffix {
99
10- excel ("xlsx" ),
11- csv ("csv" ),
12- json ("json" ),
10+ excel (". xlsx" ),
11+ csv (". csv" ),
12+ json (". json" ),
1313 ;
1414
1515 private final String suffix ;
Original file line number Diff line number Diff line change 11package info .xiaomo .gengine .utils ;
22
3+ import java .io .File ;
4+ import lombok .extern .slf4j .Slf4j ;
5+
6+ @ Slf4j
37public class ConfigUtil {
48
5- /**
6- * 获取项目目录下的game-conf文件夹目录
7- *
8- * @return
9- */
10- public static String getConfigPath () {
11- return System .getProperty ("user.dir" ) + "/game-conf" ;
12- }
9+ /**
10+ * 获取项目目录下的game-conf文件夹目录
11+ *
12+ * @return
13+ */
14+ public static String getConfigPath () {
15+ File file = new File (System .getProperty ("user.dir" ));
16+ if (file .getParent () != null ) {
17+ return file .getParent () + "/game-conf/" ;
18+ }
19+ log .warn ("获取项目根节点出错:{}" , file .getPath ());
20+ return file .getPath () + "/game-conf/" ;
21+ }
1322}
Original file line number Diff line number Diff line change 33import java .io .FileInputStream ;
44import java .io .FileNotFoundException ;
55import java .io .InputStream ;
6+ import java .util .Map ;
67import lombok .extern .slf4j .Slf4j ;
78import org .yaml .snakeyaml .Yaml ;
89
910@ Slf4j
1011public class YamlUtil {
1112
13+ @ SuppressWarnings ("unchecked" )
14+ public static Map <String , Object > read (String file ) {
15+ return read (file , Map .class );
16+ }
17+
1218 public static <T > T read (String file , Class <T > clazz ) {
1319 InputStream input ;
1420 try {
Original file line number Diff line number Diff line change 11package info .xiaomo .config ;
22
3+ import java .util .Map ;
34import info .xiaomo .config .beans .ItemConfig ;
45import info .xiaomo .gengine .config .ConfigSuffix ;
56import info .xiaomo .gengine .config .annotation .ConfigFileScan ;
67import info .xiaomo .gengine .config .annotation .PackageScan ;
8+ import info .xiaomo .gengine .utils .YamlUtil ;
9+ import org .junit .Test ;
710
811/**
912 * @author YangQiang
1013 */
1114@ ConfigFileScan (value = "" , suffix = ConfigSuffix .excel )
1215@ PackageScan ("info.xiaomo.config.beans" )
1316public class ConfigDataTest {
14- public static void main (String [] args ) throws Exception {
17+
18+ @ Test
19+ public void testReadDataTable () throws Exception {
1520 ConfigDataManager dataManager = ConfigDataManager .getInstance ();
1621 // 初始化配置
22+
1723 dataManager .init ();
1824
1925 // 获取半条数据,可以筛选多个id
@@ -23,4 +29,12 @@ public static void main(String[] args) throws Exception {
2329 // 获取整张表的数据
2430 dataManager .getConfigs (ItemConfig .class ).forEach (System .out ::println );
2531 }
32+
33+
34+ @ Test
35+ public void testYaml (){
36+ Map <String , Object > read = YamlUtil .read ("/Users/ctwdevops/Workspace/game/GEngine/src/test/resources/test.yml" );
37+ System .out .println (read .get ("a" ));
38+
39+ }
2640}
Original file line number Diff line number Diff line change 1+ a : 1
2+ b : 2
3+ c : 3
You can’t perform that action at this time.
0 commit comments