我有一个数据库表与用户,我想返回所有的用户从表中我需要一个方法,返回每个用户,并能够看到该数组在 Postman 为了比较。除了其他属性外,每个用户还包含一个列表作为属性
我已经创建了一个方法,它创建了每个用户中包含的列表,每次获取用户时都需要调用该方法,尝试通过散列表进行迭代。
private BuyerDataServiceBean armaListaByAll(Map<Integer, Object> mapResults) {
Map<Integer, Object> row = new HashMap<>();
BuyerDataServiceBean buyerDataServiceBean = new BuyerDataServiceBean();
row = (Map<Integer, Object>) mapResults.get("out_cur_buyer_data");
ArrayList<BuyerDataAdressesBean> adresses = new ArrayList<>();
for (Map.Entry<Integer, Object> entry : row.entrySet()) {
buyerDataServiceBean.setBuyerId(entry.getKey());
for (int i = 0; i < row.size(); i++) {
Map<String, Object> map = (Map<String, Object>) row.get(i);
BuyerDataAdressesBean buyerDataAdressesBean = new BuyerDataAdressesBean();
if (i == 0) {
Map<String, Object> userObj = (Map<String, Object>) row.get(0);
buyerDataServiceBean.setLastName(
userObj.get("NOM_LAST_NAME") != null && !userObj.get("NOM_LAST_NAME").equals("")
? userObj.get("NOM_LAST_NAME").toString()
: "");
buyerDataServiceBean.setFirstName(
userObj.get("NOM_FIRST_NAME") != null && !userObj.get("NOM_FIRST_NAME").equals("")
? userObj.get("NOM_FIRST_NAME").toString()
: "");
buyerDataServiceBean.setPhoneNumber(userObj.get("REF_PHONE") != null && !userObj.get("REF_PHONE").equals("")
? userObj.get("REF_PHONE").toString()
: "");
buyerDataServiceBean.setIsDeleted(
userObj.get("IND_IS_DELETED") != null && !userObj.get("IND_IS_DELETED").equals("")
? userObj.get("IND_IS_DELETED").toString()
: "");
buyerDataServiceBean.setTaxId(userObj.get("REF_TAXID") != null && !userObj.get("REF_TAXID").equals("")
? userObj.get("REF_TAXID").toString()
: "");
buyerDataServiceBean.setCompany(userObj.get(" REF_COMPANY") != null && !userObj.get("REF_COMPANY").equals("")
? userObj.get("REF_COMPANY").toString()
: "");
buyerDataServiceBean.setEmailId(userObj.get("REF_EMAIL") != null && !userObj.get("REF_EMAIL").equals("")
? userObj.get("REF_EMAIL").toString()
: "");
buyerDataServiceBean.setRegistration(
userObj.get("STP_REGISTRATION") != null && !userObj.get("STP_REGISTRATION").equals("")
? userObj.get("STP_REGISTRATION").toString()
: "");
buyerDataServiceBean.setId(userObj.get("CVE_BUYER_ID") != null && !userObj.get("CVE_BUYER_ID").equals("")
? Integer.parseInt(userObj.get("CVE_BUYER_ID").toString())
: ConstantesUtil.RESP_INT_CERO);
buyerDataServiceBean.setBuyerId(userObj.get("NUM_USER_ID") != null && !userObj.get("NUM_USER_ID").equals("")
? Integer.parseInt(userObj.get("NUM_USER_ID").toString())
: ConstantesUtil.RESP_INT_CERO);
buyerDataServiceBean.setIsActive(
userObj.get("IND_IS_ACTIVE") != null && !userObj.get("IND_IS_ACTIVE").equals("")
? userObj.get("IND_IS_ACTIVE").toString()
: "");
}
buyerDataAdressesBean.setNomColony(map.get("NOM_COLONY") != null && !map.get("NOM_COLONY").equals("")
? map.get("NOM_COLONY").toString()
: "");
buyerDataAdressesBean.setNomTown(
map.get("NOM_TOWN") != null && !map.get("NOM_TOWN").equals("") ? map.get("NOM_TOWN").toString()
: "");
buyerDataAdressesBean
.setDesAddrType(map.get("DES_ADDR_TYPE") != null && !map.get("DES_ADDR_TYPE").equals("")
? map.get("DES_ADDR_TYPE").toString()
: "");
buyerDataAdressesBean.setNomStreet(map.get("NOM_STREET") != null && !map.get("NOM_STREET").equals("")
? map.get("NOM_STREET").toString()
: "");
buyerDataAdressesBean
.setNumPostalCode(map.get("NUM_POSTAL_CODE") != null && !map.get("NUM_POSTAL_CODE").equals("")
? map.get("NUM_POSTAL_CODE").toString()
: "");
buyerDataAdressesBean.setNomMunicipality(
map.get("NOM_MUNICIPALITY") != null && !map.get("NOM_MUNICIPALITY").equals("")
? map.get("NOM_MUNICIPALITY").toString()
: "");
buyerDataAdressesBean.setId(map.get("CVE_ADDR_ID") != null && !map.get("CVE_ADDR_ID").equals("")
? Integer.parseInt(map.get("CVE_ADDR_ID").toString())
: ConstantesUtil.RESP_INT_CERO);
buyerDataAdressesBean.setNumState(map.get("NUM_STATE") != null && !map.get("NUM_STATE").equals("")
? Integer.parseInt(map.get("NUM_STATE").toString())
: ConstantesUtil.RESP_INT_CERO);
adresses.add(buyerDataAdressesBean);
}
Adresses userAdresses = new Adresses();
Map<String, Object> addId = (Map<String, Object>) row.get(0);
userAdresses.setId(addId.get("NUM_ADDRESS_LIST_ID") != null && !addId.get("NUM_ADDRESS_LIST_ID").equals("")
? Integer.parseInt(addId.get("NUM_ADDRESS_LIST_ID").toString())
: ConstantesUtil.RESP_INT_CERO);
userAdresses.setAdresses(adresses);
buyerDataServiceBean.setAddressList(userAdresses);
BuyerDataServiceBean user = (BuyerDataServiceBean) entry.setValue(buyerDataServiceBean);
}
字符串
1条答案
按热度按时间kg7wmglp1#
使用下面的代码
字符串