我很惊讶,下划线(“_”)在OGNL中不起作用。 在下面的示例中,所有属性都在OGNL / ValueStack上处理,但由于下划线,属性名称appfull_name除外。
POJO SampleSdmAppsTabObj.java
import java.io.*;
import javax.persistence.*;
@SuppressWarnings("serial")
@Entity
@Table(name="SDM_APPS")
@IdClass(SdmAppsPkeyObj.class)
public class SdmAppsTabObj implements Serializable
{
//@Id
String orgid;
//@Id
String asnid;
String appfull_name;
String description;
public SdmAppsTabObj(){}
public SdmAppsTabObj
(
String inOrgId,
String inAsnId,
String inAppFullName,
String inDescription
)
{
this.OrgId = inOrgId;
this.AsnId = inAsnId;
this.AppFullName = inAppFullName;
this.Description = inDescription;
}
*/
public String getOrgid() { return orgid; }
public String getAsnid() { return asnid; }
public String getAppfullname() { return appfull_name; }
public String getDescription() { return description; }
public void setOrgid(String inOrgId ) { this.orgid = inOrgId; }
public void setAsnid(String inAsnId ) { this.asnid = inAsnId; }
public void setAppfullname(String inAppFullName ) { this.appfull_name = inAppFullName; }
public void setDescription(String inDescription ) { this.description = inDescription; }
//Override equals() and hashCode()
@Override
public boolean equals(Object inObject)
{
if (this == inObject) { return true; }
if (inObject == null) { return false; }
if (!(inObject instanceof SdmAppsTabObj)) { return false; }
SdmAppsTabObj other = (SdmAppsTabObj) inObject;
if( orgid == null )
if( other.orgid != null ) { return false; }
else if( !orgid.equals(other.orgid) ) { return false; }
if( asnid == null )
if( other.asnid != null ) { return false; }
else if( !asnid.equals(other.asnid) ) { return false; }
return true;
}
public int hashCode()
{
final int prime = 31;
int result = 1;
result = prime * result + ((orgid == null) ? 0 : orgid.hashCode());
result = prime * result + ((asnid == null) ? 0 : asnid.hashCode());
return result;
}
}
SdmAppsAction.java
import SdmAppsTabObj;
import SdmAppsPkeyObj;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
public class SdmAppsAction extends ActionSupport implements ModelDriven<SdmAppsTabObj>{
private static final long serialVersionUID = 1L;
SdmAppsTabObj lSdmAppsTabObj = new SdmAppsTabObj();
public String execute() throws Exception {
return SUCCESS;
}
public SdmAppsTabObj getModel() {
return lSdmAppsTabObj;
}
}
sdm_apps_add.jsp
.....
<h2>Add Apps</h2>
<s:form action="sdmAppsAction" >
<s:textfield name="orgid" label="Org" />
<s:textfield name="asnid" label="Asn" value=""/>
<s:textfield name="appfull_name" label="App name" value=""/>
<s:textfield name="description" label="Desc" value=""/>
<s:submit />
</s:form>
.....
sdm_apps_success.jsp
.....
<h2>Apps Details</h2>
Org : <s:property value="orgid" /><br>
Asn : <s:property value="asnid" /><br>
App name : <s:property value="appfull_name" /><br>
Desc : <s:property value="description" /><br>
.....
答案 0 :(得分:2)
appfull_name的getter是
public String getAppfullname();
而不是:
public String getAppfull_name();
此外,setter的名称不正确。