java.sql.SQLException: 无效的列类型: 1111

在使用Mybaits Plus更新数据时报错:

2018-09-05 10:55:40.712 DEBUG 15828 --- [nio-8110-exec-1] c.c.x.s.m.A.updateAllColumnById          : ==>  Preparing: UPDATE ais0060 SET TENANT_ID=?,LIFNR=?,NAME1=?,ORT01=?,TELF1=?,del_flag=?,remarks=?,create_by=?,create_date=?,update_by=?,update_date=? WHERE id=? 
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.type.TypeException: Could not set parameters for mapping: ParameterMapping{property='et.tenantId', mode=IN, javaType=class java.lang.Object, jdbcType=null, numericScale=null, resultMapId='null', jdbcTypeName='null', expression='null'}. Cause: org.apache.ibatis.type.TypeException: Error setting null for parameter #1 with JdbcType OTHER . Try setting a different JdbcType for this parameter or a different jdbcTypeForNull configuration property. Cause: java.sql.SQLException: 无效的列类型: 1111
	at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:77)
	at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:446)
	at com.sun.proxy.$Proxy124.update(Unknown Source)
	at org.mybatis.spring.SqlSessionTemplate.update(SqlSessionTemplate.java:294)
	at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:62)  

原因为TENANT_ID字段为null。

网查原因大多给出Mybatis修改XML中的SQL写法,但是Mybatis Plus基础CRUD不需要手写SQL,整了半天,找到一种解决方法:

    /**
     * 租户ID
     */
    @TableField(value = "TENANT_ID", el = "tenantId, jdbcType=VARCHAR")
    private String tenantId;

  

在@TableField注解中增加{对象.属性}。同时,el的更多用法:

    /**
     * <p>
     * 当该Field为类对象时, 可使用#{对象.属性}来映射到数据表.
     * </p>
     * <p>
     * 支持:@TableField(el = "role, jdbcType=BIGINT)<br>
     * 支持:@TableField(el = "role, typeHandler=com.baomidou.springcloud.typehandler.PhoneTypeHandler")
     * </p>
     */
    String el() default "";

  

Mybatis写SQL语句修改方法参见:https://blog.csdn.net/stronglyh/article/details/45369611

jdbcType介绍参见:https://www.cnblogs.com/tongxuping/p/7134113.html

猜你喜欢

转载自www.cnblogs.com/beiifeng/p/9591078.html