Java :-
productAssoc = delegator.findByPrimaryKey("ProductAssoc", UtilMisc.toMap("productId", productId, "productIdTo", productIdTo, "productAssocTypeId", productAssocTypeId, "fromDate", fromDate));
Groovy :-
productAssoc = delegator.findByPrimaryKey("ProductAssoc", ['productId' : productId, 'productIdTo' : productIdTo, 'productAssocTypeId' : productAssocTypeId, 'fromDate' : fromDate]);
การเชคค่า Null
Java :- if (payment == null) continue; Groovy :- if (!payment) continue;
การเชคค่า Null และ Size ที่มากกว่า 0
Java:-
if (glAccounts != null && glAccounts.size() > 0) {
// code here.
}
Groovy :-
if (glAccounts) {
// code here.
}
การกำหนดวันที่
Java :-
nowDate = UtilDateTime.nowDate();
context.put("nowDate", nowDate);
Groovy :-
context.nowDate = UtilDateTime.nowDate();
การกำหนดวันที่พร้อมเวลา
Java :- String nowTimestampString = UtilDateTime.nowTimestamp().toString(); Groovy :- context.nowTimestampString = UtilDateTime.nowTimestamp().toString();
การใช้(;)เมื่อสิ้นสุดคำสั่ง
Java :- import org.ofbiz.product.inventory.InventoryWorker; Groovy :- import org.ofbiz.product.inventory.InventoryWorker
การวนลูปเพื่มดึงข้อมูล
Java :-
List invoiceItemTypes = new LinkedList();
i = invoiceItemTypes.iterator();
while ( i ) {
GenericValue invoiceItemType = i.next();
}
Groovy :-
invoiceItemTypes.each {
GenericValue invoiceItemType = it;
}
หรือ
invoiceItemTypes.each { invoiceItemType ->
// code here.
}
การค้นหาข้อมูล findByAnd
Java:-
invoiceAppls = delegator.findByAnd("PaymentApplication", UtilMisc.toMap("invoiceId", invoiceId, "invoiceItemSeqId", null));
Groovy :-
invoiceAppls = delegator.findByAnd("PaymentApplication", [invoiceId : invoiceId, invoiceItemSeqId : null]);
การสร้าง Map เปล่าๆ
Java:- product = new HashMap(); // Empty map Groovy :- product = [:] ;
การสร้าง List เปล่าๆ
Java :- products = new ArrayList(); // Empty list Groovy :- products = [] ;
การเชคค่าว่างใน List กำหนดให้ invoiceItemTypeOrgsList เป็น object ของ List
Java :-
if (UtilValidate.isNotEmpty(invoiceItemTypeOrgsList)) {
// code here.
}
Groovy :-
if (invoiceItemTypeOrgsList) {
// code here.
}
การเชคค่าว่างใน Map กำหนดให้ invoiceItemTypeOrgsMap เป็น object ของ Map
Java :-
if (UtilValidate.isNotEmpty(invoiceItemTypeOrgsMap)) {
// code here.
}
Groovy :-
if (invoiceItemTypeOrgsMap) {
// code here.
}
การเชคค่าว่างใน String
Java :-
if (paymentId != null) {
Groovy :-
if (paymentId) {
การเรียกค่าข้อมูลจากในรูปแบบของ Map
Java:-
invoiceId = parameters.get("invoiceId");
Groovy :-
invoiceId = parameters.invoiceId;
0 comments:
Post a Comment