regex 数组列表的Struts 2 json结果

k7fdbhmy  于 2023-05-19  发布在  其他
关注(0)|答案(1)|浏览(102)

我有一个ArrayList数组ArrayList<[obj1,obj2]>。这里的obj1obj2是不同的Java实体,这个列表是由HQL查询返回的。
如何在struts.xml文件中循环遍历此列表以将其作为JSON结果发送?
我尝试了下面的组合,但没有运气:

  1. ^itemList\[\d+\]\.^\[\0+\].id--> id是实体的属性
  2. ^itemList\[\d+\]\.\0\.id
  3. ^itemList\[\d+\]\.co.id--> co = hql中的实体别名
  4. ^itemList\[\d+\]\[0].id
  5. ^itemList\[\d+\]\.\[\0+\].id
  6. ^itemList\[\d+\]\.[0].id

编辑:

我在struts.xml中使用它如下:

<action name="list-view-op-cost-management_cons"  class="com.eves.aixis.s2.action.billing.ConsignmentBillingGridAction" method="listViewOperationalCostForManagement">
            <result type="json">
                <param name="ignoreHierarchy">false</param>
                <param name="includeProperties">
                    viewType,
                    searchType,
                    searchValue,
                    service,
                    page,
                    total,
                    records,
                    ^itemList\[\d+\]\.^\[\0+\].id,
                    reqaction_,
                    actionResult,
                    ^errorList\[\d+\]
                    
                </param>
            </result>
        </action>

编辑:

Obj1 = Consignment(Bussiness entity)

使用字段:

private Integer id;
    private String consignmentNo;
    private Customer sender;
    private Contact senderContact;
    private Pickup pickupRef;
    private Receiver receiver;
    private List<Invoice> invoiceList;
    private ConsignmentStatus consignmentStatus;
    private Boolean invoiceToReiver;
    private String deliveryInstruction;
    private String customerReference;
    private List<PackageDescription> packageDescription;// actual package info
    private List<PackageDescription> custPackage;//use in ecp (external customer portal) and use in inquiry given customer package details
    private List<PackageDescription> revProtPackages;//revenue protection packages
    
    private Receiver deliveryAddress;
    private List<ConsignmentTrack> connoteTrack;
    private ProductType productType;
    private List<Commodity> commodities;
    private PreBriefDeskVerify briefDeskVerify;

obj2 = SalesOrder(Bussiness entity)

使用字段:

private Long id;
    private SalesOrderType salesItemType;
    
    private Consignment salesItem;  
                                    
    private MasterAirwayBill mawb; 
    private Pickup pickupSI;
    private Delivery deliverySI;

    
    private WHSalesItem whSalesItem;
    
    
    private Job job;
    private SCMBillingState billingState;
    
    
    private Tariff tariff; 

    private Tariff tariffForPrinciples; 
   

    private List<SalesOrderLineItem> salesOrderItemList;
    private String remarks;
    private SalesOrderStatus salesOrderStatus;
sc4hvdpw

sc4hvdpw1#

参数includeProperties包含一个正则表达式列表,用于匹配可序列化到JSON对象的属性。这个正则表达式应该与你的属性名匹配,试试看

^itemList.*$

如果你只想要id属性,那么你可以尝试

^itemList.*\.id$

相关问题