gpt4 book ai didi

java - 在 Struts 2 中使用 ModelDriven 访问 POJO 属性?

转载 作者:行者123 更新时间:2023-11-29 08:54:30 26 4
gpt4 key购买 nike

我在 Struts2 中使用 ModelDriven,这样我的模型对象内部就有另一个具有属性的对象。我正在进行 AJAX 调用并希望我的模型对象由用户填充。

JSP:

<s:select list="#session.circleIdNameMap"
headerKey="-1" headerValue="Select Circle"
name="id.circleId" id="selectCircleDropDown"
onchange="findTspNameIdMap(this.value)">
</s:select>

JS:

 $.ajax({   
type: 'POST',
url: '/gma/findTspNameIdMap.action',
data:
{
id.circleId: circleId,
minNumberOc: $("[name='minNumberOc']").val(),
minDurationOc: $("[name='minDurationOc']").val(),
},

然而,在 Firebug 中我得到一个错误

SyntaxError: missing : after property id
id.circleId: circleId,

但其他直接属性如 minNumberOc 工作正常但 id.anything 不工作。我正在发布我的模型对象和 Action 类。

GmaThreshold参数:

public class GmaThresholdParameter implements Serializable {
private static final long serialVersionUID = 1L;

@EmbeddedId
private GmaThresholdParameterPK id;
//getter/setters of id

GmaThresholdParameterPK:

public class GmaThresholdParameterPK implements Serializable {

private static final long serialVersionUID = 1L;

@Column(name="CIRCLE_ID")
private int circleId;

@Column(name="TSP_ID")
private int tspId;

private String flag;
//getter/setters

Action 类:

public class ConfigureTspThresholdAction extends ActionSupport implements SessionAware, ModelDriven<GmaThresholdParameter>{

private Map<String,String> circleIdNameMap;
// MODEL object
GmaThresholdParameter gmaThresholdParameters = new GmaThresholdParameter();
.....
...
public GmaThresholdParameter getGmaThresholdParameters() {
return gmaThresholdParameters;
}


public void setGmaThresholdParameters(
GmaThresholdParameter gmaThresholdParameters) {
this.gmaThresholdParameters = gmaThresholdParameters;
}

@Override
public GmaThresholdParameter getModel() {
return gmaThresholdParameters;
}

如何设置id对应的属性?为什么在 Firebug 中会报错?

最佳答案

Why is it giving an error in Firebug?

因为你在下面的语句中有一个尾随逗号

minDurationOc: $("[name='minDurationOc']").val(),

关于java - 在 Struts 2 中使用 ModelDriven 访问 POJO 属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20965826/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com