mybatis 中foreach传入的是对像List时怎么办
1个回答
展开全部
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>
collection就是传过来的集合,item就是集合里的元素,
#{paramPage.order.orderStr}应该换成#{item}
试试看
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>
collection就是传过来的集合,item就是集合里的元素,
#{paramPage.order.orderStr}应该换成#{item}
试试看
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |