ibatis parameterClass是2个参数类型时!!

发布于 2021-11-26 10:50:48 字数 6760 浏览 763 评论 3

<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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

心舞飞扬 2021-11-28 18:13:56

你确认parameterClass 可以传递两个,用逗号分隔?

等你爱我 2021-11-27 06:38:41

引用来自“抓瓦工人”的评论

Caused by: java.lang.ClassNotFoundException: users,tname

夜血缘 2021-11-27 00:33:21

换mybatis吧……

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文