我有一个Java类,可将信息链接到数据库中的表。
类Fmpolicy.java
:
@Entity
@Table(name = "fmpolicy")
public class Fmpolicy implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "FMPID")
private Long fmpid;
@Basic(optional = false)
@NotNull
@Column(name = "NODEID")
private long nodeid;
@Basic(optional = false)
@NotNull
@Column(name = "FMPUGID")
private long fmpugid;
@Basic(optional = false)
@NotNull
@Column(name = "FMPUGTYPE")
private int fmpugtype;
@Basic(optional = false)
@NotNull
@Column(name = "FMPVIEW")
private boolean fmpview;
@Basic(optional = false)
@NotNull
@Column(name = "FMPREVISE")
private boolean fmprevise;
@Basic(optional = false)
@NotNull
@Column(name = "FMPDOWNLOAD")
private boolean fmpdownload;
@ManyToOne(fetch=FetchType.EAGER)
@JoinColumn(referencedColumnName="nodeid", name="NODEID", updatable=false, insertable=false)
private Node fmn;
public Fmpolicy() {
}
public Fmpolicy(Long fmpid) {
this.fmpid = fmpid;
}
public Fmpolicy(Long fmpid, long nodeid, long fmpugid, int fmpugtype, boolean fmpview, boolean fmprevise, boolean fmpdownload) {
this.fmpid = fmpid;
this.nodeid = nodeid;
this.fmpugid = fmpugid;
this.fmpugtype = fmpugtype;
this.fmpview = fmpview;
this.fmprevise = fmprevise;
this.fmpdownload = fmpdownload;
}
public Long getFmpid() {
return fmpid;
}
public void setFmpid(Long fmpid) {
this.fmpid = fmpid;
}
public long getNodeid() {
return nodeid;
}
public void setNodeid(long nodeid) {
this.nodeid = nodeid;
}
............
上面只是其中的一部分。然后,我有一个JSP页面,我想从此Fmpolicy
创建实例对象。
Jsp页面:
long nodeID = Long.parseLong(request.getParameter("nodeID"));
long graphID = Long.parseLong(request.getParameter("graphID"));
Fmpolicy fp = new Fmpolicy(nodeID);
fp.getNodeid();
........
//this part should be able to check FMPVIEW column for it's nodeID respectively rather than FMPID
if(fp.getFmpview(nodeID)==true) {
// do something if true
}
问题是当我尝试调试它时,nodeID的值正确返回,但由 fmpid 代替。例如,nodeID = 123,但它将值传递给了 fmpid = 123 。
因此,我无法检索要实现目标的特定ID。如何正确将nodeID传递给对象,以便检查条件?
我做错了什么?
答案 0 :(得分:1)
您拥有的单个arg构造函数将以fmpid
作为参数并将其分配给private Long fmpid;
public Fmpolicy(Long fmpid) {
this.fmpid = fmpid;
}
要设置nodeId
,请创建一个没有arg构造函数的对象,并使用setter方法设置nodeId
Fmpolicy fp = new Fmpolicy();
fp.setNodeid(nodeID);