Last active
July 26, 2017 01:23
-
-
Save JunNakamura/a8e9cd35d04f33586778 to your computer and use it in GitHub Desktop.
Revisions
-
JunNakamura revised this gist
Jul 26, 2017 . No changes.There are no files selected for viewing
-
Jun Nakamura created this gist
Mar 4, 2016 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,18 @@ class User { /** * ユーザID */ private String id; /** * ユーザ名 */ private String name; /** * 削除フラグ */ private boolean deleted; /* 中略 */ } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,12 @@ // サンプルなので、guavaつかってそれっぽいのを作成 // 実際には設定ファイルなどから生成をするのを想定 Map<String,String> converter = ImmutableMap.Builder() .put("ユーザID", "id") .put("ユーザ名", "name") .put("削除フラグ", "deleted") .build(); public String[] toPropertyHeader(String[] header, Map<String,String> converter) { /* converterをつかって、和名をカラム名に変化したarrayを生成 */ } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,14 @@ File file = new File("user.csv"); try(ICsvBeanReader beanReader = new CsvMapReader(new FileReader(file), CsvPreference.EXCEL_PREFERENCE)) { String[] header = beanReader .getHeader(true); // CSVの和名ヘッダーを取得 String[] propertyHeader = toPropertyHeader(header, converter); //和名ヘッダーをカラム名ヘッダーに変換 User user; while((user= beanReader .read(User.class, propertyHeader)) != null) { Logger.info("user {}", user); } } catch (Exception e) { Logger.error("reading is failed.", e); } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1 @@ customerNo,firstName,lastName,birthDate,mailingAddress,married,numberOfKids,favouriteQuote,email,loyaltyPoints This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,3 @@ ユーザID,ユーザ名,削除フラグ 001,ユーザその1,false 002,ユーザ2,true