Mybatis框架--Ibatis框架踩坑01 -- Java中BigInteger类型字段问题!

 

       在Mybatis框架、 Ibatis框架中, 不支持Java中的 java.math.BigInteger 类型字段, 支持 java.math.BigDecimal 类型字段。若Java实体类中,使用 java.math.BigInteger 类型字段,在使用 Mybatis、Ibatis框架进行数据处理时,会报错。

 

        Mybatis中文在线网中介绍的Mybatis支持的数据类型与Java数据类型对应关系网址: Mybatis 3|配置 -- XML配置 

在下图所示部位,可以找到Mybatis中支持的数据类型与Java中数据类型对应关系。

 

Mybatis框架--Ibatis框架踩坑01 -- Java中BigInteger类型字段问题!_第1张图片

 

 

       在我开发过程中,与公司老员工交流过程中,兵哥建议我,Mysql中数据类型为 BigInteger、BigDecimal 的字段,Java中的属性使用 java.lang.Long、 java.lang.Integer、 java.lang.Dubbo、java.lang.Short  的数据类型定义。

 

       在开发过程中,当我使用 Java.math.BigInteger数据类型时,Ibatis/Mybatis框架log日志报错内容如下所示。其中,prodAttrValueId属性采用Java中的 java.math.BigInteger 数据类型定义。     

 

Exception in thread "main" java.lang.ExceptionInInitializerError
Caused by: org.springframework.beans.factory.BeanCreationException: 

Error creating bean with name 'prodAttrService' defined in class path resource [applicationContext.xml]: 
	Cannot resolve reference to bean 'prodAttrDao' while setting bean property 'prodAttrDao'; 
	nested exception is org.springframework.beans.factory.BeanCreationException: 
	Error creating bean with name 'prodAttrDao' defined in class path resource [applicationContext.xml]: 
	Cannot resolve reference to bean 'sqlMapClient' while setting bean property 'sqlMapClient'; 
	nested exception is org.springframework.beans.factory.BeanCreationException: 
	Error creating bean with name 'sqlMapClient' defined in class path resource [applicationContext.xml]: 

Invocation of init method failed; 
nested exception is org.springframework.core.NestedIOException: 
Failed to parse config resource: class path resource [sqlMapConfig.xml]; 
nested exception is 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/select'.  
Cause: com.ibatis.common.beans.ProbeException: There is no READABLE property named 'prodAttrValueId' in class 'java.math.BigInteger'

	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:329)
	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:107)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1393)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1134)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:522)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461)
	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:626)
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
	at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:139)
	at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:83)
	at com.web.asiainfo.main.ProductRun.(ProductRun.java:29)
	
	
	
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'prodAttrDao' defined in class path resource [applicationContext.xml]: Cannot resolve reference to bean 'sqlMapClient' while setting bean property 'sqlMapClient'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlMapClient' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is org.springframework.core.NestedIOException: Failed to parse config resource: class path resource [sqlMapConfig.xml]; nested exception is 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/select'.  Cause: com.ibatis.common.beans.ProbeException: There is no READABLE property named 'prodAttrValueId' in class 'java.math.BigInteger'
	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:329)
	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:107)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1393)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1134)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:522)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461)
	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:323)
	... 15 more



 

举一个简单的例子:

    Java实体类

 

 

 

 未完待续.........................

 

 

 

 

你可能感兴趣的:(IT之旅,Java求学路,Mybatis框架,IBatis框架)