如果lazy=true(默认是true)
比如
<class name="LinkPerson" table="linkPerson">
<id name="id">
<generator class="identity"/>
</id>
<many-to-one name="company" class="Company" column="company_id" />
</class>
那么
action
public String list(){
SysUser sysUser = SessionUtils.getSysUserFormSession(httpServletRequest);
if (sysUser!=null) {
List<LinkPerson> linkPersons = new ArrayList(sysUser.getLinkPersons());
if (linkPersons!=null && linkPersons.size()!=0) {
httpServletRequest.setAttribute("linkPersons", linkPersons);
}
return "list";
}
return "toLogin";
}
list.jsp
<s:if test="%{#request.linkPersons!=null}">
<s:iterator value="%{#request.linkPersons}" var="linkPerson">
<s:property value="%{#linkPerson.company.name}"/>
<s:property value="%{#linkPerson.company.name}"/>不显示,debug发现action的save()方法中,linkPerson中的company是代理类,里面的属性都是null,自然<s:property value="%{#linkPerson.company.name}"/>不显示,如下图
而改成
<class name="LinkPerson" table="linkPerson">
<id name="id">
<generator class="identity"/>
</id>
<many-to-one name="company" class="Company" column="company_id" lazy="false"/>
</class>
则linkPerson中的company是实际的类,里面属性都在