无法从类型Officer

时间:2017-08-04 04:24:50

标签: spring model-view-controller

我正在尝试插入以下代码中的值:

public int create(Officer officer) {
     String sql = "insert into officer values(" + officer.getOfficer_id() + ", " + officer.getCollege_id() + ", " + Officer.getUnit_id() + ", " + officer.getRole_id() + ")";
     return template.update(sql);
}

1 个答案:

答案 0 :(得分:1)

这应该是编译错误。 getUnit_id不是静态方法,因此您需要使用Officer实例调用它。

public int create(Officer officer) { String sql = "insert into officer values(" + officer.getOfficer_id() + ", " + officer.getCollege_id() + ", " + officer.getUnit_id() + ", " + officer.getRole_id() + ")"; return template.update(sql); }