[英]spring mvc use model.addAttribute(nav) can not get the parent class’s attributes in jsp with ${nav.id}
i am new Spring learner. 我是新的春季学习者。
how can i get all attributes(include parent) 我如何获取所有属性(包括父项)
in below there are my code,see this code,please: 在下面有我的代码,请参见以下代码:
Controller:
@RequestMapping("/nav/addOrEdit")
public String navAdd(Nav nav,ModelMap model){
if(nav.getId()!=null&&nav.getId()!=0) {
nav=siteService.getNav(nav.getId());
model.addAttribute(nav);
System.out.println("nav.id:"+nav.getId());
}
return "CJ/nav/addOrEdit";
}
Nav:
public class Nav extends PO{
private static final long serialVersionUID = -13569672251584L;
protected String code;
@NotEmpty
protected String name;
public String getCode() { return code; }
public void setCode(String code) { this.code = code; }
public String getName() { return name; }
public void setName(String name) { this.name = name; }
}
PO:
public class PO implements Serializable {
private static final long serialVersionUID = 4572077184754045588L;
protected Long Id;
public Long getId() {return Id;}
public void setId(Long id) {Id = id;}
}
jsp:
console.log("${nav}"); -->Nav{code=1, name=test},
no id,how can i get the parent class's attributes? 没有ID,如何获取父类的属性?
In your case you are adding your parent class object
in Map
. 在您的情况下,您要在
Map
中添加父类object
。 So you can not directly access that object
instead of putting object directly into Map
add that object with some key and directly access it on JSP. 因此,您不能直接访问该
object
而不能将对象直接放入Map
,并使用一些键添加该对象并在JSP上直接访问它。 ie 即
model.addAttribute("nav",nav);
More details check Spring Documention of Model interface 更多详细信息请查看Spring Documentation of Model接口
Now you can access your value directly. 现在,您可以直接访问您的价值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.