问题描述
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN" "http://ibatis.apache.org/dtd/sql-map-2.dtd"><sqlMap><!-- 为Person类设置一个别名 --><typeAlias alias="user" type="com.lt.ibatis.pojo.user"/><!-- 配置表和类之间的映射关系 --><resultMap class="com.lt.ibatis.pojo.user" id="userMap"><result property="userid" column="userid"/><result property="username" column="username"/><result property="password" column="password"/><result property="phone" column="phone"/><result property="fax" column="fax"/></resultMap><!-- 验证帐号密码 --><select id="queryAccount" parameterClass="java.lang.String" resultClass="com.lt.ibatis.pojo.User"><![CDATA[SELECT * FROM USERTAB WHERE USERID=#USERID# AND PASSWORD=#PASSWORD#]]></select></sqlMap>这是我的 User.xml 表映射文件 报的错误是:Exception in thread "main" java.lang.NoClassDefFoundError: com/lt/ibatis/pojo/user (wrong name: com/lt/ibatis/pojo/User)at java.lang.ClassLoader.defineClass1(Native Method)at java.lang.ClassLoader.defineClass(Unknown Source)at java.security.SecureClassLoader.defineClass(Unknown Source)at java.net.URLClassLoader.defineClass(Unknown Source)at java.net.URLClassLoader.access$100(Unknown Source)at java.net.URLClassLoader$1.run(Unknown Source)at java.security.AccessController.doPrivileged(Native Method)at java.net.URLClassLoader.findClass(Unknown Source)at java.lang.ClassLoader.loadClass(Unknown Source)at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)at java.lang.ClassLoader.loadClass(Unknown Source)at com.ibatis.common.resources.Resources.classForName(Resources.java:260)at com.ibatis.sqlmap.engine.builder.xml.SqlMapParser$14.process(SqlMapParser.java:374)at com.ibatis.common.xml.NodeletParser.processNodelet(NodeletParser.java:121)at com.ibatis.common.xml.NodeletParser.process(NodeletParser.java:84)at com.ibatis.common.xml.NodeletParser.process(NodeletParser.java:102)at com.ibatis.common.xml.NodeletParser.parse(NodeletParser.java:72)at com.ibatis.common.xml.NodeletParser.parse(NodeletParser.java:51)at com.ibatis.sqlmap.engine.builder.xml.SqlMapParser.parse(SqlMapParser.java:51)at com.ibatis.sqlmap.engine.builder.xml.SqlMapConfigParser$11.process(SqlMapConfigParser.java:410)at com.ibatis.common.xml.NodeletParser.processNodelet(NodeletParser.java:121)at com.ibatis.common.xml.NodeletParser.process(NodeletParser.java:84)at com.ibatis.common.xml.NodeletParser.process(NodeletParser.java:102)at com.ibatis.common.xml.NodeletParser.parse(NodeletParser.java:72)at com.ibatis.common.xml.NodeletParser.parse(NodeletParser.java:51)at com.ibatis.sqlmap.engine.builder.xml.SqlMapConfigParser.parse(SqlMapConfigParser.java:86)at com.ibatis.sqlmap.client.SqlMapClientBuilder.buildSqlMapClient(SqlMapClientBuilder.java:63)at com.lt.dao.QuoteDao.queryAccount(QuoteDao.java:19)at com.lt.dao.TestDao.main(TestDao.java:15)好象是路径问题,本人刚学习ibatis,之前学的一个DEMO都成功了,这次自己写的就出问题了?有人能回答下吗?
解决方案
是不是类名的大小写搞错了,比如说在<resultMap class="com.lt.ibatis.pojo.user" id="userMap"> <result property="userid" column="userid"/> <result property="username" column="username"/> <result property="password" column="password"/> <result property="phone" column="phone"/> <result property="fax" column="fax"/> </resultMap> 应该是 class="com.lt.ibatis.pojo.User",做什么都要认真啊
解决方案二:
java.lang.NoClassDefFoundError,错误很明显是你的类的路径没放对,仔细检查下!