question
Today, when using mybatis in springboot, the fields cannot be automatically mapped. The version of mybatis is 3.5.11. The database is named according to the underscore, and the java class follows the hump naming method, as follows
Write the mapper.xml file as follows to query all data
<select id="queryAllGoods" resultType="com.ttpfx.seckill.entity.Goods">
select *
from t_goods
</select>
The result of the final query does not perform field mapping, only the id is obtained, and the output is as follows
solve
After reading the official document mybatis3 automatic mapping , I found the reason
By default, mybatis only ignores case when performing automatic mapping, and does not handle underscores. You need to set mapUnderscoreToCamelCase to true.
The final solution is to configure in the yaml configuration file, as follows
mybatis:
configuration:
map-underscore-to-camel-case: true
Run the test program again and the problem is successfully resolved