I, ~ March 2013 Graduated from the Faculty of Arts and Sciences ~ April 2018 Infrastructure SIer # Linux or Azure May 2018-WEB engineer # I wanted to be able to develop Following the transition, I am studying Java in a highly acclaimed business.
If you can learn how to develop I would like to do my best so that I can acquire full-stack skills.
Please note that there may be many descriptions for beginners.
Process the information obtained by crawling and The process of inserting into multiple tables
① Create a common map and enter information (2) Create a Map for A table, insert the Map of (1), process the Map for A table, and insert it into the A table. ③ Create a map for B table, insert the map of ①, process the map for B table and insert it into the B table.
I wanted to do that
Execute the following method
public void putMain() {
Map<String, Object> insertData = new HashMap<>();
insertData.put("aaa","aaa");
insertData.put("bbb","bbb");
insertData.put("ccc","ccc");
putA(insertData);
putB(insertData);
}
public void putA(Map<String, Object> insertData) {
Map<String, Object> aData = new HashMap<>();
aData = insertData;
aData.remove("bbb");
insert(aData);
}
public void putB(Map<String, Object> insertData) {
Map<String, Object> bData = new HashMap<>();
bData = insertData;
bData.remove("aaa");
insert(bData);
}
insertData | aData | bData |
---|---|---|
aaa | aaa | |
bbb | bbb | |
ccc | ccc | ccc |
insertData | aData | bData |
---|---|---|
aaa | ||
ccc | ccc | ccc |
And so on The contents of the common table have changed.
public void putMain() {
Map<String, Object> insertData = new HashMap<>();
insertData.put("aaa","aaa");
insertData.put("bbb","bbb");
insertData.put("ccc","ccc");
putA(insertData);
putB(insertData);
}
public void putA(Map<String, Object> insertData) {
Map<String, Object> aData = new HashMap<>(insertData);
aData.remove("bbb");
insert(aData);
}
public void putB(Map<String, Object> insertData) {
Map<String, Object> bData = new HashMap<>(insertData);
bData.remove("aaa");
insert(bData);
}
Instead of assigning after declaring xData If you give insertData as an argument when declaring xData It worked as expected.
I haven't studied why this is so, so I don't know. .. .. Please tell me your seniors > <
Recommended Posts