網(wǎng)站首頁 編程語言 正文
一、簡介:mybatis是支持屬性使用駝峰的命名
如下java代碼
public class Role {
private Integer id;
private String roleName;
private String roleKey;
private Integer orderNum;
private Integer roleType;
private String remark;
...省略set,get方法
}
列名是有下劃線的
像上面這樣設(shè)計是需要配置下劃線與駝峰式命名規(guī)則的映射
mapUnderscoreToCamelCase:是否啟用下劃線與駝峰式命名規(guī)則的映射(如first_name => firstName)
<setting name="mapUnderscoreToCamelCase" value="true"/>
二、在SSM整合中的配置
方式一:
在applicationContext-dao.xml中引入mybatis配置
<!-- 配置sqlSessionFactory -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<!-- 數(shù)據(jù)庫連接池 -->
<property name="dataSource" ref="dataSource"/>
<!-- 加載Mybatis全局配置文件 -->
<property name="configLocation" value="/WEB-INF/classes/mybatis/SqlMapConfig.xml"/>
</bean>
SqlMapConfig.xml
<?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>
<!--開啟駝峰命名轉(zhuǎn)換-->
<setting name="mapUnderscoreToCamelCase" value="true"/>
</settings>
</configuration>
方式二:
在applicationContext-dao.xml中直接配置
<bean class="org.mybatis.spring.SqlSessionFactoryBean" id="factory">
<property name="dataSource" ref="dataSource"/>
<property name="typeAliasesPackage" value="com.glc.domain"/>
<property name="configuration">
<bean class="org.apache.ibatis.session.Configuration">
<property name="mapUnderscoreToCamelCase" value="true"/>
</bean>
</property>
</bean>
三、親測代碼配置文件spring-mybatis.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd">
<!-- 掃描service包下所有使用注解的類型 -->
<context:component-scan base-package="com.chatRobot.service"/>
<!-- 配置數(shù)據(jù)庫相關(guān)參數(shù)properties的屬性:${url} -->
<context:property-placeholder location="classpath:jdbc.properties"/>
<!-- 數(shù)據(jù)庫連接池 -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="${jdbc.driver}"/>
<property name="jdbcUrl" value="${jdbc.url}"/>
<property name="user" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
<property name="maxPoolSize" value="${c3p0.maxPoolSize}"/>
<property name="minPoolSize" value="${c3p0.minPoolSize}"/>
<property name="autoCommitOnClose" value="${c3p0.autoCommitOnClose}"/>
<property name="checkoutTimeout" value="${c3p0.checkoutTimeout}"/>
<property name="acquireRetryAttempts" value="${c3p0.acquireRetryAttempts}"/>
</bean>
<!-- 配置SqlSessionFactory對象 -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<!-- 注入數(shù)據(jù)庫連接池 -->
<property name="dataSource" ref="dataSource"/>
<!-- 掃描model包 使用別名 -->
<property name="typeAliasesPackage" value="com.chatRobot.model"/>
<!-- 掃描sql配置文件:mapper需要的xml文件 -->
<property name="mapperLocations" value="classpath:mapper/*.xml"/>
<property name="configuration">
<bean class="org.apache.ibatis.session.Configuration">
<!--mybatis支持屬性使用駝峰的命名-->
<property name="mapUnderscoreToCamelCase" value="true"/>
</bean>
</property>
</bean>
<!-- 配置掃描Dao接口包,動態(tài)實現(xiàn)Dao接口,注入到spring容器中 -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<!-- 注入sqlSessionFactory -->
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>
<!-- 給出需要掃描Dao接口包 -->
<property name="basePackage" value="com.chatRobot.dao"/>
</bean>
<!-- 配置事務(wù)管理器 -->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<!-- 注入數(shù)據(jù)庫連接池 -->
<property name="dataSource" ref="dataSource"/>
</bean>
<!-- 配置基于注解的聲明式事務(wù) -->
<tx:annotation-driven transaction-manager="transactionManager"/>
</beans>
原文鏈接:https://blog.csdn.net/qq_36501591/article/details/134759440
- 上一篇:沒有了
- 下一篇:沒有了
相關(guān)推薦
- 2022-07-28 詳解Python中4種超參自動優(yōu)化算法的實現(xiàn)_python
- 2022-09-25 ECharts如何在pycharm中運行
- 2022-11-19 Golang接口使用教程詳解_Golang
- 2023-01-01 解決React報錯Property?'X'?does?not?exist?on?type?'HTML
- 2022-08-01 基于Python編寫一個二維碼生成器_python
- 2023-01-21 Python?configparser模塊的用法示例代碼_python
- 2022-09-14 利用Pandas實現(xiàn)對數(shù)據(jù)進行移動計算_python
- 2022-10-05 python中內(nèi)置庫os與sys模塊的詳細介紹_python
- 欄目分類
-
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細win安裝深度學習環(huán)境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡單動態(tài)字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支