我有一个名为 GmaThreshold.java
的 EJB:
package cdot.oss.cmsat.gma.ejb.entity;
@Entity
@Table(name="GMA_THRESHOLDS")
@NamedQuery(
name = "getThresholdParameters",
query = "SELECT gmaTh.maxDurationIc, gmaTh.distinctBnumberRatio "
+ "WHERE gmaTh.id.circleId=?1 AND gmaTh.id.tspId=?2 "
+ "AND gmaTh.id.flag=?3 ")
public class GmaThreshold implements Serializable {
@EmbeddedId
private GmaThresholdPK id;
@Column(name="DISTINCT_BNUMBER_RATIO")
private String distinctBnumberRatio;
@Column(name="MAX_DURATION_IC")
private BigDecimal maxDurationIc;
public GmaThresholdPK getId() {
return this.id;
}
public void setId(GmaThresholdPK id) {
this.id = id;
}
public String getDistinctBnumberRatio() {
return this.distinctBnumberRatio;
}
public void setDistinctBnumberRatio(String distinctBnumberRatio) {
this.distinctBnumberRatio = distinctBnumberRatio;
}
public BigDecimal getMaxDurationIc() {
return this.maxDurationIc;
}
public void setMaxDurationIc(BigDecimal maxDurationIc) {
this.maxDurationIc = maxDurationIc;
}
}
我希望在JSP中由用户填写实体类的参数。
<s:textfield id="thresholdParameter_1"
name="gmathreshold.distinctBnumberRatio">
</s:textfield></td>
并在我的操作类中保留 bean 的实例作为成员变量。
我正在使用Struts2
。
这是像这样填充 EJB 实体的正确方法吗?
我应该使用 DTO 吗?
编辑:我在文本字段中从用户那里得到distinctBnumberRatio
,因此它将是一个String
,但是在我的bean中它是一个BigDecimal
。如何解决这个问题?
最佳答案
自 3.0 起,EJB 都是简单的 POJO,因此可以在 JSP 中使用 bean。通过评估
中的 OGNL 表达式"gmathreshold.distinctBnumberRatio"
将调用相应的 getter 和 setter。然后您可以更新 EJB 容器。 DTO 不属于任何容器,除非您手动或由另一个容器管理它们,并且也可以由表示层使用。两者都是正确的。
关于java - 使用struts2用户填充的实体bean?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20881724/