前端页面如何遍历后台给的Map

markYun 发布于 2013/08/05 10:55
阅读 3K+
收藏 0
java代码:

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;


import com.hc.base.tools.TimeTool;
import com.hc.ibk.hshop.HsBaseBean;


/**
 * 门店基础信息表实体对象
 * 
 */
@Entity
@Table(name = "sub_baseinfo")
public class SubBaseinfo extends HsBaseBean {


/**
* 公司邮箱

*/
@Column(name = "email")
private String email;
/**
* 固定电话

*/
@Column(name = "telphone")
private String telphone;
/**
* 手机号码

*/
@Column(name = "mobilephone")

private String mobilephone;



代码2:

/**
 * 门店基础信息表Action对象
 * 
 */
@SuppressWarnings("serial")
@Controller
public class SubBaseinfoAction extends HCBaseAction implements
ModelDriven<SubBaseinfo> {


private SubBaseinfo form;
private int sub_id = 0;
 
@Resource
SubBaseinfoSer subBaseinfoSer;


private Map<String, List<SubBaseinfo>> map = new HashMap<String, List<SubBaseinfo>>();


/**
* 门店管理列表

* @return
*/
@Action(value = "store_m", results = {
@Result(name = "success", location = "/asserts/pages/companymanger/store_manage/store_m.jsp"),
@Result(name = "input", location = "login", type = "redirectAction") })
public String store_m() {
try {
Object obj = session.get(ParasDef.COMPANY_OBJECT);
if (obj == null) {
return INPUT;
} else {
map = subBaseinfoSer.querySubs4Map((MbaseInfo) obj);
// list = subBaseinfoSer.queryFormList((MbaseInfo) obj);
}
} catch (Exception e) {
log.error("查询并组装门店对象信息异常!", e);
}
return SUCCESS;
}




我前端写了一些应该是写错了。始终没有拿到对象。


 <c:forEach items="${sub_baseinfo}" var="entry">  
     <c:out value="${entry[mobilephone]}" />   
</c:forEach>  

  <small>&nbsp;共6 ${form.sub_shop_name}个门店</small> 


求教怎么获取后台的map对象的内容。,

以下是问题补充:

@markYun:后台有get set方法我没贴。有数据的。 写了半天。就是没得到数据 是我页面不知道怎么获取 (2013/08/05 11:02)
@markYun:已经搞定: <s:iterator value="map" id="column"> <div> <dt class="city-tit"> <input type="checkbox" id="0" name="0" value="on" style="margin-right: 25px;" class="se-sinput"> <s:property value="key" /> </dt> <s:iterator value="#column.value" status="s"> <dd class="se-incar se-z-index"> <dl> <dd class="l0"> <input type="checkbox" name="shop_id[]" value="79202382" class="se-sinput"> </dd> <dd class="se-state"></dd> <dd class="l1"> <a target="_blank" href="http://t.zuzuche.com/companies/company_shop.php?shop_id=79202382"><s:property value="sub_shop_name" /> </a> </dd> <dd class="l2s"> <s:property value="detail_addr" /> </dd> <dd class="l3 c77"> <s:property value="telphone" /> </dd> <dd class="l3"></dd> <dd class="l5 r"> <a class="edit_btn" href="javascript:;">修改</a> <span class="se-line"></span> <a target="iframe_alert" onclick="delete_shop(79202382, this);" href="javascript:;">删除</a> </dd> </dl> <div class="clear"></div> </dd> </s:iterator> <div class="clear"></div> </div> </s:iterator> (2013/08/05 13:11)
加载中
0
不正常的物种
不正常的物种

你的map没有放到session,request里面啊,当然拿不到,request.setAttribute("sub_baseinfo", map);

<c:forEach items="${sub_baseinfo}" var="entry">  
     <c:out value="${entry.email}" />   
</c:forEach>  

0
你要爪子
你要爪子


  <c:set value="${entry[mobilephone]}"  var='entry'/>   


<c:out value="${entry.key}"/>

<c:out value="${entry.value}"/>

0
黄龍
黄龍

1.sub_baseinfo这什么东西啊?不是遍历map么?

2.${entry[mobilephone]}这个mobilephone是常量字符串还是变量啊?

0
markYun
markYun
<s:iterator value="map" id="column">
<div>
<dt class="city-tit">
<input type="checkbox" id="0" name="0" value="on"
style="margin-right: 25px;" class="se-sinput">
<s:property value="key" />
</dt>
<s:iterator value="#column.value" status="s">
<dd class="se-incar se-z-index">
<dl>
<dd class="l0">
<input type="checkbox" name="shop_id[]"
value="79202382" class="se-sinput">
</dd>
<dd class="se-state"></dd>
<dd class="l1">
<a target="_blank"
href="http://t.zuzuche.com/companies/company_shop.php?shop_id=79202382"><s:property
value="sub_shop_name" /> </a>
</dd>
<dd class="l2s">
<s:property value="detail_addr" />
</dd>
<dd class="l3 c77">
<s:property value="telphone" />
</dd>
<dd class="l3"></dd>
<dd class="l5 r">
<a class="edit_btn" href="javascript:;">修改</a> <span
class="se-line"></span> <a target="iframe_alert"
onclick="delete_shop(79202382, this);"
href="javascript:;">删除</a>
</dd>
</dl>
<div class="clear"></div>
</dd>
</s:iterator>
<div class="clear"></div>
</div>  
</s:iterator>
返回顶部
顶部