在你看到的這個方法中,我根據pincode或voen從oracle資料庫中的程式接收資料。
@Override
public List<BaseClass> getCustomerInfo(String pinCode, String voen) throws SQLException, JsonProcessingException {
List<BaseClass> customerInfos = new ArrayList<>();
Query q = em.createNativeQuery("select CUST_INFO_COURT.GET_CUSTOMER_INFO('" pinCode "','" voen "') from dual");
List objectArray = q.getResultList();
for (Object object : objectArray) {
if (object != null) {
Clob clob = (Clob) object;
String arrayJsonData = clob.getSubString(1, (int) clob.length());
final ObjectMapper objectMapper = new ObjectMapper();
CustomerInfo[] langs = objectMapper.readValue(arrayJsonData, CustomerInfo[].class);
List<CustomerInfo> langList = new ArrayList(Arrays.asList(langs));
for (CustomerInfo customerInfo : langList) {
customerInfos.add(customerInfo);
}
return customerInfos;
}
}
return new ArrayList<>();
}
但有一個問題。問題是我可以根據pin碼接收資料,但是當我搜索為voen時,我無法獲取值。當我根據密碼搜索時,我的查詢是這樣作業的。
Hibernate:
select
CUST_INFO_COURT.GET_CUSTOMER_INFO('',
'null')
from
dual
和輸出中的資料如下:
[
{
"full_name": "",
"doc_sr": "",
"doc_id": "",
"customer_id": ,
"pin_code": "",
"voen": "",
"position": null
}
]
當我根據 voene 搜索時,它會做同樣的事情。
Hibernate:
select
CUST_INFO_COURT.GET_CUSTOMER_INFO('null',
'')
from
dual
和輸出中的資料如下:
[]
有一個問題,我認為是 SQL 注入。我正在考慮使用該setParameter()方法以這種方式發送引數,但我不知道如何將其應用于此代碼。
uj5u.com熱心網友回復:
您可以使用這樣的引數:
Query q = em.createNativeQuery(
"select CUST_INFO_COURT.GET_CUSTOMER_INFO(?,?) from dual");
q.setParameter(1, pinCode);
q.setParameter(2, voen);
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/361921.html
下一篇:如何將查詢結果存盤在陣列中?
