MyBatis+Oracle 使用注解式实现 insert

代码:

@Override
@Insert("INSERT INTO DAT_FLOOR " +
        " (floorId, FLOORNAME, FLOORTYPE, FLOORLOCATION, STATUS, CREATER, CREATETIME," +
        " MODIFIER, MODIFYTIME, BELONGPAGE, USERGROUP, RELEASESYSTEM) " +
        " VALUES (#{floor.floorId}, #{floor.floorName}, #{floor.floorType}, #{floor.floorLocation}, #{status}, " +
        " #{floor.creater}, #{floor.createTime}, #{floor.modifier}, #{floor.modifyTime}, #{floor.belongPage}, " +
        " #{floor.userGroup}, #{floor.releaseSystem}) ")
@Options(useGeneratedKeys=true, keyProperty="id")
int insert(@Param("floor")Floor floor);

出现异常: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: 无效的列类型

添加失败了,原因是传过来的字段为null

解决方法:给可能为null的字段添加 jdbcType

@Insert("INSERT INTO DAT_FLOOR " +
        " (floorId, FLOORNAME, FLOORTYPE, FLOORLOCATION, STATUS, CREATER, CREATETIME," +
        " MODIFIER, MODIFYTIME, BELONGPAGE, USERGROUP, RELEASESYSTEM) " +
        " VALUES (#{floorId,jdbcType = VARCHAR}, #{floorName,jdbcType = VARCHAR}, #{floorType,jdbcType = VARCHAR}, #{floorLocation,jdbcType = VARCHAR}, #{status}, " +
        " #{creater}, #{createTime}, #{modifier}, #{modifyTime}, #{belongPage}, " +
        " #{userGroup,jdbcType = VARCHAR}, #{releaseSystem,jdbcType = VARCHAR}) ")
@Options(useGeneratedKeys=false, keyProperty="id")
int insert1(Floor floor);

你可能感兴趣的:(MyBatis+Oracle 使用注解式实现 insert)