Search code examples
mybatisspring-mybatisapplication.properties

MyBatis map-underscore-to-camel-case not working


I am using MyBatis 2.0.0 and have problem: I have a userId and status field that need to retrieve data so I'm using Mybatis for it. but when I try to get the data the MyBatis don't work and I keep getting the same error. I've tried to add the lines to application.properties

#mybatis entity scan packages
mybatis.type-aliases-package=com.cnoga.**.dao

#Mapper.xml location
mybatis.mapper-locations=classpath*:/mybatis/**/*.xml
mybatis.configuration.map-underscore-to-camel-case=true

but nothing happend and I still get my error. I even tried to create the mybatis-config.xml like this:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
    <settings>
        <setting name="mapUnderscoreToCamelCase" value="true" />
    </settings>
</configuration>

and add this line to application.properties instead the lines above:

"mybatis.config-location=classpath:/mybatis-config.xml"

The mapper file:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.proj.user.dao.UserMapper" >

  <select id="query4Regist" resultType="java.util.Map" parameterType="java.util.Map" >
   select u.user_id userId, 
          status
     from t_user u 
     left join t_user_group ug on u.user_id = ug.user_id 
    where u.is_del  = 1
      and u.status between 0 and 4
      and ( 
            u.email = #{account,jdbcType=NVARCHAR}
            <if test="countryCode != null and countryCode != ''">
               or (u.mobile = #{account,jdbcType=NVARCHAR} and u.country_code = #{countryCode,jdbcType=NVARCHAR})
            </if>
          )
      and (u.region_name = #{regionName} or ug.group_id = 7 or ug.group_id = 8)
      order by u.user_id desc offset 0 rows fetch next 1 rows only
  </select>  
</mapper>

Solution

  • I solved the problem! The problem was using the map functions. To use MYBATIS I built struct only for the values ​​I wanted to transfer and I just changed in all the places where I called the map functions to get data from the new struct