我是mybatis新手。我的类中有一个 java BigInteger 属性。相关的mysql字段类型是BigInt。当我要使用 xml 配置文件将记录插入数据库时,它会给出类似 'There was no TypeHandler found forparameter id'
的异常。
我的 xml 插入查询是,
INSERT INTO xX_ (
id, date, name, connection)
VALUES (
#{id}, #{date}, #{name}, #{connection}
)
请帮助我解决此问题,而无需更改 DTO 类的类型。
最佳答案
请看这里:http://mybatis.github.io/mybatis-3/configuration.html#typeHandlers
要使用 BigInteger 和 BigInt,您必须编写自定义 typeHandler,如下所示:
// ExampleTypeHandler.java
@MappedTypes(BigInteger.class)
public class BigIntegerTypeHandler extends BaseTypeHandler<BigInteger> {
//implement all methods
}
像这样配置你的 config.xml:
<!-- mybatis-config.xml -->
<typeHandlers>
<typeHandler handler="your.packadge.BigIntegerTypeHandler"/>
</typeHandlers>
一定有帮助。
关于java - Mybatis插入参数类型转换错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20884141/