ibatis parameterClass是2个参数类型时!!
<sqlMap namespace="T_USER" > <typeAlias alias="users" type="com.bean.TUsers"/> <resultMap id="result_base" class="users"> <result property="name" column="name"/> <result property="age" column="age"/> <result property="carnum" column="carnum" /> </resultMap> <typeAlias alias="tname" type="com.bean.TabName"/> <resultMap id="t_name" class="tname"> <result property="tabName" column="tabName" /> </resultMap> <statement id="statementName" parameterClass="users,tname"> INSERT INTO $tabname$ (name,age,carnum) VALUES ('$name$','$age$','$carnum$') </statement> </sqlMap>
public interface IBasicDao { Object insert(Object obj); } public class BasicDao extends ConnectionFactory implements IBasicDao{ @Override public Object insert(Object obj) { Object rest = null; try { rest = super.getSqlMapClient().insert("T_USER.statementName", obj); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } return rest; } } public class Test { public static void main(String[] args) { IBasicDao dao = new BasicDao(); TUsers t = new TUsers(); t.setName("zhangsan6"); t.setAge(10); t.setCarnum(new BigDecimal(8)); TabName tabName = new TabName(); tabName.setTabName("t_users"); System.out.println(dao.insert(new Object[]{t,tabName})); System.out.println("--------------------------------"); } }
错误信息:
Exception in thread "main" java.lang.RuntimeException: Error occurred. Cause: com.ibatis.common.xml.NodeletException: Error parsing XML. Cause: java.lang.RuntimeException: Error parsing XPath '/sqlMapConfig/sqlMap'. Cause: com.ibatis.common.xml.NodeletException: Error parsing XML. Cause: java.lang.RuntimeException: Error parsing XPath '/sqlMap/statement'. Cause: com.ibatis.sqlmap.client.SqlMapException: Error. Could not initialize class. Cause: java.lang.ClassNotFoundException: users,tname
at com.ibatis.sqlmap.engine.builder.xml.SqlMapConfigParser.parse(SqlMapConfigParser.java:49)
at com.ibatis.sqlmap.client.SqlMapClientBuilder.buildSqlMapClient(SqlMapClientBuilder.java:63)
at com.utils.ConnectionFactory.getSqlMapClient(ConnectionFactory.java:59)
at com.dao.BasicDao.insert(BasicDao.java:16)
at com.test.Test.main(Test.java:23)
Caused by: com.ibatis.common.xml.NodeletException: Error parsing XML. Cause: java.lang.RuntimeException: Error parsing XPath '/sqlMapConfig/sqlMap'. Cause: com.ibatis.common.xml.NodeletException: Error parsing XML. Cause: java.lang.RuntimeException: Error parsing XPath '/sqlMap/statement'. Cause: com.ibatis.sqlmap.client.SqlMapException: Error. Could not initialize class. Cause: java.lang.ClassNotFoundException: users,tname
at com.ibatis.common.xml.NodeletParser.parse(NodeletParser.java:53)
at com.ibatis.sqlmap.engine.builder.xml.SqlMapConfigParser.parse(SqlMapConfigParser.java:46)
... 4 more
Caused by: java.lang.RuntimeException: Error parsing XPath '/sqlMapConfig/sqlMap'. Cause: com.ibatis.common.xml.NodeletException: Error parsing XML. Cause: java.lang.RuntimeException: Error parsing XPath '/sqlMap/statement'. Cause: com.ibatis.sqlmap.client.SqlMapException: Error. Could not initialize class. Cause: java.lang.ClassNotFoundException: users,tname
at com.ibatis.common.xml.NodeletParser.processNodelet(NodeletParser.java:123)
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)
... 5 more
Caused by: com.ibatis.common.xml.NodeletException: Error parsing XML. Cause: java.lang.RuntimeException: Error parsing XPath '/sqlMap/statement'. Cause: com.ibatis.sqlmap.client.SqlMapException: Error. Could not initialize class. Cause: java.lang.ClassNotFoundException: users,tname
at com.ibatis.common.xml.NodeletParser.parse(NodeletParser.java:53)
at com.ibatis.sqlmap.engine.builder.xml.SqlMapParser.parse(SqlMapParser.java:40)
at com.ibatis.sqlmap.engine.builder.xml.SqlMapConfigParser$10.process(SqlMapConfigParser.java:270)
at com.ibatis.common.xml.NodeletParser.processNodelet(NodeletParser.java:121)
... 9 more
Caused by: java.lang.RuntimeException: Error parsing XPath '/sqlMap/statement'. Cause: com.ibatis.sqlmap.client.SqlMapException: Error. Could not initialize class. Cause: java.lang.ClassNotFoundException: users,tname
at com.ibatis.common.xml.NodeletParser.processNodelet(NodeletParser.java:123)
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)
... 12 more
Caused by: com.ibatis.sqlmap.client.SqlMapException: Error. Could not initialize class. Cause: java.lang.ClassNotFoundException: users,tname
at com.ibatis.sqlmap.engine.builder.xml.SqlStatementParser.resolveClass(SqlStatementParser.java:89)
at com.ibatis.sqlmap.engine.builder.xml.SqlStatementParser.parseGeneralStatement(SqlStatementParser.java:64)
at com.ibatis.sqlmap.engine.builder.xml.SqlMapParser$17.process(SqlMapParser.java:342)
at com.ibatis.common.xml.NodeletParser.processNodelet(NodeletParser.java:121)
... 16 more
Caused by: java.lang.ClassNotFoundException: users,tname
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at com.ibatis.common.resources.Resources.classForName(Resources.java:267)
at com.ibatis.sqlmap.engine.builder.xml.SqlStatementParser.resolveClass(SqlStatementParser.java:84)
... 19 more
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你确认parameterClass 可以传递两个,用逗号分隔?
引用来自“抓瓦工人”的评论
Caused by: java.lang.ClassNotFoundException: users,tname
换mybatis吧……