一、组装参数的学习
首先是查询条件,对于查询条件,需要判断是否从前端传递空值?——怎么处理查询空值?
当然可以一个一个进行判断,但是这样代码会导致很多,可以统一处理,形成一个公共方法。
1、 单个处理的方式:
调用工具方法判空(底层:判断是否是null 和空)
/** UtilValidate类. */
/** Check whether string s is NOT empty. */
public static boolean isNotEmpty(String s) {
return (s != null) && s.length() > 0;
}
/** Check whether collection c is NOT empty. */
public static <E> boolean isNotEmpty(Collection<E> c) {
return (c != null) && !c.isEmpty();
}
/** Check whether charsequence c is NOT empty. */
public static <E> boolean isNotEmpty(CharSequence c) {
return ((c != null) && (c.length() > 0));
}
if (UtilValidate.isNotEmpty(startDate)) { condList.add(EntityCondition.makeCondition(PackagePrepayFields.REPAY_APP_DATE, EntityOperator.GREATER_THAN_EQUAL_TO, startDate)); }
1、分页
1.1 服务(方法名称)对应XML
入参
<attribute name="viewSize" type="Integer" mode="IN" optional="true" description="条数" /> <attribute name="viewIndex" type="Integer" mode="IN" optional="true" description="页码" />
出参
<attribute name="returnCode" type="Map" mode="OUT" optional="true" description="标准返回状态数据"/> <attribute name="totalSize" type="Integer" mode="OUT" optional="true" description="返回总条数" /> <--此处注意出参的大小写 -->
1.2 Java代码的输出
result.put("list", pagedList.getData());
result.put("totalSize", pagedList.getSize());
2、 EntityQuery的学习
// 带分页参数
PagedList<GenericValue> pagedList = EntityQuery.use(delegator) .select(columns) .from(PackagePrepayFields.COM_MESSAGE_INFO_TEXT_THREE) .where(condList) .cursorScrollInsensitive() .queryPagedList(viewIndex - 1, viewSize);
// 不带分页
List<GenericValue> list =EntityQuery.use(delegator)
.select(columns)
.from(PackagePrepayFields.COM_MESSAGE_INFO_TEXT_THREE)
.where(condList)
.queryList();