網(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方法
}
列名是有下劃線的
像上面這樣設計是需要配置下劃線與駝峰式命名規(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ù)庫相關參數(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>
<!-- 配置事務管理器 -->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<!-- 注入數(shù)據(jù)庫連接池 -->
<property name="dataSource" ref="dataSource"/>
</bean>
<!-- 配置基于注解的聲明式事務 -->
<tx:annotation-driven transaction-manager="transactionManager"/>
</beans>
原文鏈接:https://blog.csdn.net/qq_36501591/article/details/134759440
- 上一篇:沒有了
- 下一篇:沒有了
相關推薦
- 2022-10-23 Android?Handler源碼深入探究_Android
- 2022-06-08 ASP.NET?Core中的靜態(tài)文件_基礎應用
- 2022-05-07 Qt+OpenCV實現(xiàn)目標檢測詳解_C 語言
- 2023-01-12 C語言求字符串長度的四種方法實例代碼_C 語言
- 2024-02-26 gitlab合并分支
- 2022-06-29 Python解決非線性規(guī)劃中經(jīng)濟調(diào)度問題_python
- 2022-07-12 windows11下的dockerDesktop4.8.2資源目錄掛載
- 2023-12-21 uniapp 清除文件緩存
- 欄目分類
-
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細win安裝深度學習環(huán)境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結構-簡單動態(tài)字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支