猿问

mybatis 中foreach传入的是对像List时怎么办?

public class ParamOrder {
    private String orderStr; // 排序字段名字(与返回字段对应)
    private String orderType; // 排序方式

    public String getOrderStr() {
        return orderStr;
    }

    public void setOrderStr(String orderStr) {
        this.orderStr = orderStr;
    }

    public String getOrderType() {
        return orderType;
    }

    public void setOrderType(String orderType) {
        this.orderType = orderType;
    }
}
public class ParamPage {
    private int page; // 查询的页码
    private int pageSize; // 每页显示的条数
    private List<ParamOrder> order; // 排序的list

    public int getPage() {
        return page;
    }

    public void setPage(int page) {
        this.page = page;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public List<ParamOrder> getOrder() {
        return order;
    }

    public void setOrder(List<ParamOrder> order) {
        this.order = order;
    }

}

 

<if test="paramPage.order!=null">
                <foreach collection="paramPage.order" index="index" item="item"
                    open="order by" separator="," close=" ">
                    #{paramPage.order.orderStr} ASC
                </foreach>
            </if>
繁花如伊
浏览 589回答 1
1回答

米琪卡哇伊

collection就是传过来的集合,item就是集合里的元素, #{paramPage.order.orderStr}应该换成#{item} 你再试试看
随时随地看视频慕课网APP

相关分类

Java
我要回答