1 回答

TA貢獻1936條經驗 獲得超7個贊
從您的 servlet 請求中獲取參數:
String cartItemsParameter= request.getParameter("cartitems");
使用方法:
findRexExpList(cartItemParameter, "\\D+\\d+");
方法代碼:
private static List<String> findRexExpList(String text, String regExp) {
List<String> result = new ArrayList<>();
Pattern pattern = Pattern.compile(regExp);
Matcher matcher = pattern.matcher(text);
while (matcher.find()) {
String group = matcher.group();
result.add(group);
}
return result;
}
此方法返回帶有分隔字符串的列表
對于商店數據:
List<String> carts = findRexExpList(cartItemParameter, "\\D+\\d+");
String[] cartPrices = request.getParameter("cartprice").split(",");
for(int i=0; i<cartPrices.length; i++){
String cart = carts.get(i);
String price = cartPrices[i];
//insert cart and price
}
添加回答
舉報