Struts2对值栈中的List便利,格式都正确却遍历不出来数据的问题

具体情况如下:

模型驱动Friend:

public class Friend implements Serializable{
	private String fName;
	private String fPlace;
	private String fPhone;
	public Friend() {
	}
	public String getfName() {
		return fName;
	}
	public void setfName(String fName) {
		this.fName = fName;
	}
	public String getfPlace() {
		return fPlace;
	}
	public void setfPlace(String fPlace) {
		this.fPlace = fPlace;
	}
	public String getfPhone() {
		return fPhone;
	}
	public void setfPhone(String fPhone) {
		this.fPhone = fPhone;
	}
	
}
Action如下:

public class FriendAction extends ActionSupport{
	private List<Friend> fList;
	
	public List<Friend> getfList() {
		return fList;
	}

	public void setfList(List<Friend> fList) {
		this.fList = fList;
	}

	@Override
	public String execute() throws Exception {
		FriendInfo info = new FriendInfo();
		//查询出所有好友
		fList = info.selectAll();
		return SUCCESS;
	}
}
在JSP用如下代码 遍历时,却不出现数据:

<s:iterator value="flist">
    	fName:<s:property value="fName"/>
    	fPlace:<s:property value="fPlace"/> 
    	fPhone:<s:property value="fPhone"/> 
 </s:iterator>


解决方案:

原因原来是模型驱动的问题:

把模型驱动改成如下:

public class Friend implements Serializable{
	private String name;
	private String place;
	private String phone;
	public Friend() {
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getPlace() {
		return place;
	}
	public void setPlace(String place) {
		this.place = place;
	}
	public String getPhone() {
		return phone;
	}
	public void setPhone(String phone) {
		this.phone = phone;
	}
}
出现这种情况主要是编码习惯的问题。在设置模型驱动的字段时,最好不要用fName这种格式,在jsp页面遍历的时候如果用的是fName,实际上对应模型驱动里面的getFName()方法,但我们的模型驱动
是getfName(),因此数据遍历不出来。



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值