MyBatis: underscore not mapped to camelcase

rhandom picture rhandom · Sep 29, 2014 · Viewed 10.4k times · Source

My problem is simple. I have a column name product_name in my product table in my mysql database but in my Product class (java), camelcase is used in productName. MyBatis is not mapping product_name to productName. Any solution for this? I had no problem in Hibernate before but right now I need to use mybatis for development

Answer

rimsky picture rimsky · Mar 19, 2015

I know this is old but for those that may come across this, MyBatis supports mapping underscores to camel case

config.xml

<configuration>
    <settings>
        <setting name="mapUnderscoreToCamelCase" value="true"/>
    </settings>
    ...
</configuration>

Then your sql can look like:

select product_name, product_description, ...
from products

or even just

select *
from products