mybatis自定义的SQL语句中,如select语句,如果数据库表的字段为驼峰命名,即如img_address这样的形式,那么select语句执行的结果会变成null。

  解决办法是在配置文件中加上开启驼峰映射的配置信息。根据配置文件的类型分为以下两种:

1.在.properties文件中添加:

mybatis.configuration.map-underscore-to-camel-case=true 

 但如果已经在.properties中配置了mybatis.config-location=classpath:mybatis/mybatis-config.xml这样的语句,就应该使用下一种方式,即把配置信息写在.xml中。

2.在mybatis的配置文件,如mybatis-config.xml中进行配置: 

<configuration>
    <!-- 开启驼峰映射 ,为自定义的SQL语句服务-->
    <!--设置启用数据库字段下划线映射到java对象的驼峰式命名属性,默认为false-->  
    <settings>
      <setting name="mapUnderscoreToCamelCase" value="true"/>
    </settings>
 
</configuration>

 

相关文章:

  • 2021-09-26
  • 2021-08-05
  • 2022-02-03
  • 2022-01-19
  • 2022-12-23
  • 2022-01-19
  • 2021-11-13
  • 2021-05-12
猜你喜欢
  • 2021-10-17
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-03
  • 2022-02-23
相关资源
相似解决方案