SpringBoot与MyBatis-Plus整合的配置文件,以及SSM相关配置文件

  • SpringBoot与MyBatis-Plus整合的配置文件:介绍
spring:
  application:
    name: zlx-mybatisplus-springboot
  datasource:
    driver-class-name: com.mysql.jdbc.Driver
    url: jdbc:mysql://127.0.0.1:3306/mp?useUnicode=true&characterEncoding=utf8&autoReconnect=true&allowMultiQueries=true&useSSL=false
    username: root
    password: 你的数据库密码

mybatis-plus:
  config-location: classpath: mybatis-config.xml #MyBatis 配置文件位置,如果您有单独的 MyBatis 配置,请将其路径配置到 configLocation 中
  #注意:你在使用的时候请将mybatis后面的"\"删除掉!
  mapper-locations: classpath*:mybatis\/*.xml     #MyBatis Mapper 所对应的 XML 文件位置,如果您在 Mapper 中有自定义方法(XML 中有自定义实现),需要进行该配置,告诉 Mapper 所对应的 XML 文件位置。
  type-aliases-package: com.zlx.mybatis.pojo     # MyBaits 别名包扫描路径,通过该属性可以给包中的类注册别名,注册后在 Mapper 对应的 XML 文件中可以直接使用类名,而不用使用全限定的类名(即 XML 中调用的时候不用包含包名)
  #全局配置文件 这是springBoot整合MyBatis-Plus中的配置 (如果你是Spring整合MyBatis-Plus那么你就需要另外写一个mybatis-plus.config.xml全局配置文件,请参考:https://mybatis.org/mybatis-3/zh/configuration.html)
  configuration:
    map-underscore-to-camel-case: false          # 关闭自动驼峰映射,该参数不能和mybatis-plus.config-location同时存在
    cache-enabled: false                         #全局性地开启或关闭所有映射器配置文件中已配置的任何缓存。 默认为true
  #具体请参考官方文档: [https://mp.baomidou.com/config/#globalconfig-2]
  global-config:
  	#请参考MyBatis-Plus官方文档:[https://mp.baomidou.com/config/#dbconfig]
    db-config:
      id-type: auto           # 全局配置主键类型(默认为auto),设置后,即可省略实体对象中的@TableId(type = IdType.AUTO)配置
      table-prefix: tb_       # 表名前缀,全局配置后可省略 @TableName()配置
      table-underline: true   #表名、是否使用下划线命名,默认数据库表使用下划线命名  
  • Spring整合MyBatis-Plus进行全局配置的时候需要写一个mybatisplus-config.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>
	<!--具体的配置内容请参考mybatis-plus官方文档[https://mp.baomidou.com/config/#configuration-2]-->
</configuration>
  • 如果你是用的是SSM框架,那么你需要写一个spring-mvc.xml配置文件:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<beans xmlns="http://www.springframework.org/schema/beans"
            xmlns:context="http://www.springframework.org/schema/context"
            xmlns:mvc="http://www.springframework.org/schema/mvc"
            xmlns:p="http://www.springframework.org/schema/p"
            xmlns:websocket="http://www.springframework.org/schema/websocket"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xsi:schemaLocation="http://www.springframework.org/schema/beans
               http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
               http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
               http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
               http://www.springframework.org/schema/websocket http://www.springframework.org/schema/websocket/spring-websocket-4.0.xsd">
	<!-- 这里使用MP提供的sqlSessionFactory,完成了Spring与MP的整合-->
	<bean id="sqlSessionFactory" class="com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean">
		<!-- 请参考MyBatis-Plus官方文档:https://mp.baomidou.com/config/#%E4%BD%BF%E7%94%A8%E6%96%B9%E5%BC%8F -->
		<!--MyBatis配置文件位置,如果您有单独的MyBatis 配置,请将其路径配置到 configLocation 中 -->
		<property name="configLocation" value="classpath:mybatis-config.xml"/>
		<!--MyBatis Mapper 所对应的 XML 文件位置,如果您在 Mapper 中有自定义方法(XML 中有自定义实现),需要进行
			该配置,告诉 Mapper 所对应的 XML 文件位置。-->
			<!--Maven 多模块项目的扫描路径需以 classpath*: 开头 (即加载多个 jar 包下的 XML 文件)-->
		<property name="mapperLocations" value="classpath*:mybatis/*.xml"/>
		<!--MyBaits 别名包扫描路径,通过该属性可以给包中的类注册别名,注册后在 Mapper 对应的 XML 文件中可以直接使
			用类名,而不用使用全限定的类名(即 XML 中调用的时候不用包含包名)-->
		<property name="typeAliasesPackage" value="com.baomidou.mybatisplus.samples.quickstart.entity"/>
		<!-- 配置数据源 -->
    	<property name="dataSource" ref="dataSource"/>
		<!-- 具体请参考官方文档: https://mp.baomidou.com/config/#globalconfig-2 -->
    	<property name="globalConfig">
      		<bean class="com.baomidou.mybatisplus.core.config.GlobalConfig">
				<!-- 请参考MyBatis-Plus官方文档:https://mp.baomidou.com/config/#dbconfig -->
        		<property name="dbConfig">
        			<bean class="com.baomidou.mybatisplus.core.config.GlobalConfig$DbConfig">
						<!--全局配置主键类型(默认为auto),设置后,即可省略实体对象中的@TableId(type = IdType.AUTO)配置-->
            			<property name="idType" value="AUTO"/>
						<!-- 表名前缀,全局配置后可省略 @TableName()配置。 -->
            			<property name="tablePrefix" value="tb_"/>
						<!-- 表名、是否使用下划线命名,默认数据库表使用下划线命名 -->
        				<property name="tableUnderline" value="true"/>
					</bean>
        		</property>
      		</bean>
    	</property>
  	</bean>

	<!-- 定义数据源 -->
    <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" destroy-method="close">
        <property name="url" value="jdbc:mysql://127.0.0.1:3306/mp?useUnicode=true&characterEncoding=utf8&autoReconnect=true&allowMultiQueries=true&useSSL=false"/>
        <property name="username" value="root"/>
        <property name="password" value="你的数据库密码"/>
        <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
        <property name="maxActive" value="10"/>
        <property name="minIdle" value="5"/>
    </bean>
	
</beans>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值