ofbiz 代码日记

时间:2022-05-21 23:57:11

写代码一定要尽善尽美。。

//修改方法

//条件查询 用于修改

List<GenericValue> stoList = delegator.findByAnd("YcrossStorage",UtilMisc.toMap("boxNumber","AMFU8660370"), null, false);
if(null != stoList && stoList.size() == 1) {
 //获取第一条
 GenericValue storageGV = stoList.get(0);

storageGV.set("virtualRepair", "1");  //设置字段值

delegator.store(storageGV); //修改数据

}

//sql  语句查询

String sql = "select * from YREBX_YANXIANG_INFO yx,ycross_storage ys "
     + "where yx.box_no = ys.box_number and yx.yes_status = '0' and ys.yes_storage='1'";
GenericHelperInfo helperInfo = delegator.getGroupHelperInfo("org.ofbiz");
SQLProcessor processor = new SQLProcessor(helperInfo);
ResultSet resultSet = processor.executeQuery(sql); //结果集
List<String> boxNo = resultSetToList(resultSet);

//resultSetToList:解析list

public static List resultSetToList(ResultSet rs) throws java.sql.SQLException {
if (rs == null)
return Collections.EMPTY_LIST;
ResultSetMetaData md = rs.getMetaData(); // 得到结果集(rs)的结构信息,比如字段数、字段名等
int columnCount = md.getColumnCount(); // 返回此 ResultSet 对象中的列数
List list = new ArrayList();
Map rowData = new HashMap();
while (rs.next()) {
rowData = new HashMap(columnCount);
for (int i = 1; i <= columnCount; i++) {
rowData.put(md.getColumnName(i), rs.getObject(i));
}
list.add(rowData);
System.out.println("list:" + list.toString());
}
rs.close();
return list;
}