0

我正在尝试使用 DB 测试 iBATIS。我得到一个 NullPointerException。下面是类和 iBATIS bean 配置,

  <select id="getByWorkplaceId"
  parameterClass="java.lang.Integer" resultMap="result">
  select * from WorkDetails where workplaceCode=#workplaceCode#
  </select>

  <select id="getWorkplace" resultClass="com.ibatis.text.WorkDetails">
  select * from WorkDetails
  </select>

POJO

public class WorkplaceDetail implements Serializable {
private static final long serialVersionUID = -6760386803958725272L;
private int code;
private String plant;
private String compRegNum;
private String numOfEmps;
private String typeIndst;
private String typeProd;    
private String note1;
private String note2;
private String note3;
private String note4;
private String note5;       
}

DAO实现

public class WorkplaceDetailImpl implements WorkplaceDetailsDAO {

private SqlMapClient sqlMapClient;

public void setSqlMapClient(SqlMapClient sqlMapClient) {
    this.sqlMapClient = sqlMapClient; 
    }

@Override
public WorkplaceDetail getWorkplaceDetail(int code) {
    WorkplaceDetail workplaceDetail=new WorkplaceDetail();
    try{
            **workplaceDetail= (WorkplaceDetail) this.sqlMapClient.queryForObject("workplaceDetail.getByWorkplaceId", code);**


    }catch (SQLException sqlex){
        sqlex.printStackTrace();
    }
    return workplaceDetail;
}

测试代码

public class TestDAO {

public static void main(String args[]) throws Exception{
    WorkplaceDetail wd = new WorkplaceDetail(126, "Hoonkee", "1234", "22", "Service", "Tele", "hsgd","hsgd","hsgd","hsgd","hsgd");

    WorkplaceDetailImpl impl= new WorkplaceDetailImpl();
    **impl.getWorkplaceDetail(wd.getCode());**
    impl.saveOrUpdateWorkplaceDetails(wd);
    System.out.println("dhsd"+impl);


}
}

我想选择并插入。我在上面的代码中标记为 ** ** 作为异常点

Exception in thread "main" java.lang.NullPointerException
at com.ibatis.text.WorkplaceDetailImpl.getWorkplaceDetail(WorkplaceDetailImpl.java:19)
at com.ibatis.text.TestDAO.main(TestDAO.java:11)
4

0 回答 0