我是ibatis、的新手
我用ibatis编写了一个小程序。
但我得到了以下错误。我尽力了。我不知道该如何解决。
有人能告诉我为什么会发生这种情况,以及如何避免这种错误吗?
Exception in thread "main" com.ibatis.common.exception.NestedRuntimeException: Error occurred. Cause: com.ibatis.common.xml.NodeletException: Error parsing XML. Cause: com.ibatis.common.exception.NestedRuntimeException: Error parsing XPath '/sqlMapConfig/sqlMap'. Cause: com.ibatis.common.xml.NodeletException: Error parsing XML. Cause: com.ibatis.common.exception.NestedRuntimeException: Error parsing XPath '/sqlMap/update'. Cause: com.ibatis.common.beans.ProbeException: There is no READABLE property named 'first_name' in class 'Employee'
Caused by: com.ibatis.common.beans.ProbeException: There is no READABLE property named 'first_name' in class 'Employee'
Caused by: com.ibatis.common.exception.NestedRuntimeException: Error parsing XPath '/sqlMap/update'. Cause: com.ibatis.common.beans.ProbeException: There is no READABLE property named 'first_name' in class 'Employee'
Caused by: com.ibatis.common.beans.ProbeException: There is no READABLE property named 'first_name' in class 'Employee'
Caused by:
com.ibatis.common.beans.ProbeException: There is no READABLE property named 'first_name' in class 'Employee'
代码:Employee.java包含first_name、last_name、id、salary 的getter和setter方法
employeedao.java
public static void main()
{
Reader rd=Resources.getResourceAsReader("sql-maps-config.xml");
SqlMapClient smc = SqlMapClientBuilder.buildSqlMapClient(rd);
System.out.println("Going to read records.....");
rec.setId(1);
rec.setFirstName("Roma");
smc.update("UserTEO.update", rec );
System.out.println("Record updated Successfully ");
System.out.println("Going to read records.....");
List <employeedao> ems = (List<employeedao>)
smc.queryForList("UserTEO.getAll", null);
employeedao em = null;
for (employedao e : ems) {
System.out.print(" " + e.getId());
// System.out.print(" " + e.getFirstName());
// System.out.print(" " + e.getLastName());
System.out.print(" " + e.getSalary());
em = e;
System.out.println("");
}
System.out.println("Records Read Successfully ");
}
employee.xml
<select id="getAll" resultClass="Employee">
SELECT * FROM EMPLOYEE
</select>
<update id="update" parameterClass="Employee">
UPDATE EMPLOYEE
SET first_name = #first_name#
WHERE id = #id#
</update>
</sqlMap>
getter是
public String getFirstName()
因此,属性是firstName
,而不是first_name
。
请参阅http://docs.oracle.com/javase/tutorial/javabeans/writing/properties.html