5.3 mybatis之autoMappingUnknownColumnBehavior作用-3. FAILING

下面看下最后一种,当autoMappingUnknownColumnBehavior取值FAILING时,看下如果没有完全映射上会发生情况
修改mybatis配置文件如下所示

<settings>
    <setting name="logImpl" value="STDOUT_LOGGING"/>
    <setting name="autoMappingUnknownColumnBehavior" value="FAILING"/>
</settings>

然后重新执行上面的SQL,输出结果如下所示,程序直接抛异常了,说明当库表中列不能映射到java对象中属性上,程序抛异常处理。

Logging initialized using 'class org.apache.ibatis.logging.stdout.StdOutImpl' adapter.
PooledDataSource forcefully closed/removed all connections.
PooledDataSource forcefully closed/removed all connections.
PooledDataSource forcefully closed/removed all connections.
Cache Hit Ratio [com.lzj.dao.UserDao]: 0.0
Opening JDBC Connection
Created connection 1617550648.
==>  Preparing: select * from user where id=? 
==> Parameters: 2(Integer)
<==    Columns: id, name, age
<==        Row: 2, xiaoli, 26
Exception in thread "main" org.apache.ibatis.exceptions.PersistenceException: 
### Error querying database.  Cause: org.apache.ibatis.session.SqlSessionException: Unknown column is detected on 'com.lzj.dao.UserDao.selectOne' auto-mapping. Mapping parameters are [columnName=age,propertyName=age,propertyType=null]
### The error may exist in mapper/UserMapper.xml
### The error may involve com.lzj.dao.UserDao.selectOne
### The error occurred while handling results
上一篇:RabbitMQ的自动应答和手动应答,解决重试死循环


下一篇:python 今日小知识1——parser