Mybatis开启驼峰命名,作用

  1. 在Mybatis的全局配置文件mybatis-config.xml中加入
<configuration>
    <settings>
      <setting name="mapUnderscoreToCamelCase" value="true"/>
    </settings>
</configuration>
  1. ssm整合项目中,在spring-mybatis.xml文件中
 <property name="configuration">
            <bean class="org.apache.ibatis.session.Configuration">
                <!--可以加入驼峰命名法其他mybatis的配置也就是mybatis.cfg.xml的相关配置都会转移到这里-->
                <property name="mapUnderscoreToCamelCase" value="true"/>
            </bean>
        </property>

开启驼峰命名的作用: 将数据库带有_的字段与pojo类的属性驼峰命名相关联
例如pojo类有个属性叫 userName,数据库对应字段叫user_name

<select id="queryByName" resultType="com.yangfan.pojo.User">
        select *
        from user
        <where>
            <if test="userName !=null and userName!=''">
                and user_name = #{userName}
            </if>
        </where>
    </select>

这样通过sql语句查询的结果中的带下划线字段 就可以映射上User类以驼峰命名的属性了,但是不可以写成 select * from user where userName=#{userName}

  • 13
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值