(可以跑通的,mybatis+springmvc+druid+Atomikos)基于druid ,多数据 spring

本文涉及的产品
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
RDS MySQL Serverless 高可用系列,价值2615元额度,1个月
云数据库 RDS PostgreSQL,高可用系列 2核4GB
简介:     package test.multidatasource; import org.junit.Test; import org.junit.runner.RunWith; import org.



 

 

package test.multidatasource;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import com.mifi.service.MifiDeviceService;
import com.mifidb.service.SysMifiUserAssetsService;

@RunWith(SpringJUnit4ClassRunner.class)  
@ContextConfiguration(locations = {"classpath:application*.xml"}) 
public class MultidatasourceTest {

	@Autowired
	MifiDeviceService service1;
	@Autowired
	SysMifiUserAssetsService service2;
	
	
	@Test
	public void Test(){
		try{
			
			System.out.println(service1.findAllMifiDevices().get(0).getId());
			
			System.out.println(service2.findAllSysMifiUserAssetses().get(0).getId());
		}catch(Exception e){
			e.printStackTrace();
		}
	}
	
}

 

 

#druid
druid.initialSize=5
druid.minIdle=5
druid.maxActive=15
druid.maxWait=6000
druid.timeBetweenEvictionRunsMillis=3000
druid.minEvictableIdleTimeMillis=300000

#jpa
jpa.database=org.hibernate.dialect.MySQL5Dialect

#mysql
jdbc.mysql.database=org.hibernate.dialect.MySQL5Dialect
jdbc.mysql.driverClassName=com.mysql.jdbc.Driver

#mifi database
jdbc.mifi.url=jdbc:mysql://localhost:3306/mifi?useUnicode=true&characterEncoding=utf-8
jdbc.mifi.username=root
jdbc.mifi.password=root

#mififlow database
jdbc.mififlow.url=jdbc:mysql://localhost:3306/mififlow?useUnicode=true&characterEncoding=utf-8
jdbc.mififlow.username=root
jdbc.mififlow.password=root

#mifidb database
jdbc.mififlow.url=jdbc:mysql://localhost:3306/mifidb?useUnicode=true&characterEncoding=utf-8
jdbc.mififlow.username=root
jdbc.mififlow.password=root

 

 

<?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:aop="http://www.springframework.org/schema/aop"
	xmlns:cache="http://www.springframework.org/schema/cache"
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:jee="http://www.springframework.org/schema/jee"
	xmlns:jms="http://www.springframework.org/schema/jms" xmlns:lang="http://www.springframework.org/schema/lang"
	xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:oxm="http://www.springframework.org/schema/oxm"
	xmlns:p="http://www.springframework.org/schema/p" xmlns:task="http://www.springframework.org/schema/task"
	xmlns:tx="http://www.springframework.org/schema/tx" xmlns:util="http://www.springframework.org/schema/util"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd    
    http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd    
    http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache-3.1.xsd    
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd    
    http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.1.xsd    
    http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.1.xsd    
    http://www.springframework.org/schema/jms http://www.springframework.org/schema/jms/spring-jms-3.1.xsd    
    http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-3.1.xsd    
    http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd    
    http://www.springframework.org/schema/oxm http://www.springframework.org/schema/oxm/spring-oxm-3.1.xsd    
    http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.1.xsd    
    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd    
    http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.1.xsd">

	<context:component-scan base-package="com.mifi" />
	<context:component-scan base-package="com.mifidb" />
	<context:component-scan base-package="com.mififlow" />

	<context:property-placeholder location="classpath:db-config.properties" ignore-unresolvable="true"/>

	<!--dataSource mifi -->
	<bean id="dataSourceMifi" class="com.atomikos.jdbc.AtomikosDataSourceBean"
		init-method="init" destroy-method="close">
		<property name="xaDataSourceClassName" value="com.alibaba.druid.pool.xa.DruidXADataSource" />

		<property name="uniqueResourceName" value="mifi" />
		<property name="xaProperties">
			<props>
				<prop key="url">jdbc:mysql://localhost:3306/mifi?useUnicode=true&amp;characterEncoding=utf-8</prop>
				<prop key="username">root</prop>
				<prop key="password">root</prop>
			</props>
		</property>
	</bean>


	<!--dataSource mififlow -->
	<bean id="dataSourceMifiFlow" class="com.atomikos.jdbc.AtomikosDataSourceBean"
		init-method="init" destroy-method="close">
		<property name="xaDataSourceClassName" value="com.alibaba.druid.pool.xa.DruidXADataSource" />
		<property name="uniqueResourceName" value="mififlow" />
		<property name="xaProperties">
			<props>
				<prop key="url">jdbc:mysql://localhost:3306/mifi_flow?useUnicode=true&amp;characterEncoding=utf-8</prop>
				<prop key="username">root</prop>
				<prop key="password">root</prop>
			</props>
		</property>
	</bean>

	<!--dataSource mifidb -->
	<bean id="dataSourceMifiDb" class="com.atomikos.jdbc.AtomikosDataSourceBean"
		init-method="init" destroy-method="close">
		<property name="xaDataSourceClassName" value="com.alibaba.druid.pool.xa.DruidXADataSource" />
		<property name="uniqueResourceName" value="mifidb" />
		<property name="xaProperties">
			<props>
				<prop key="url">jdbc:mysql://localhost:3306/mifi_db?useUnicode=true&amp;characterEncoding=utf-8</prop>
				<prop key="username">root</prop>
				<prop key="password">root</prop>
			</props>
		</property>
	</bean>

</beans>   

 

 

 

<?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:aop="http://www.springframework.org/schema/aop"
	xmlns:cache="http://www.springframework.org/schema/cache"
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:jee="http://www.springframework.org/schema/jee"
	xmlns:jms="http://www.springframework.org/schema/jms" xmlns:lang="http://www.springframework.org/schema/lang"
	xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:oxm="http://www.springframework.org/schema/oxm"
	xmlns:p="http://www.springframework.org/schema/p" xmlns:task="http://www.springframework.org/schema/task"
	xmlns:tx="http://www.springframework.org/schema/tx" xmlns:util="http://www.springframework.org/schema/util"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd    
    http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd    
    http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache-3.1.xsd    
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd    
    http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.1.xsd    
    http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.1.xsd    
    http://www.springframework.org/schema/jms http://www.springframework.org/schema/jms/spring-jms-3.1.xsd    
    http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-3.1.xsd    
    http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd    
    http://www.springframework.org/schema/oxm http://www.springframework.org/schema/oxm/spring-oxm-3.1.xsd    
    http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.1.xsd    
    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd    
    http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.1.xsd">
   
    <!-- mifi -->
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
		<property name="basePackage" value="com.mifi.dao" />
		<property name="sqlSessionFactory" ref="sqlSessionFactoryMifi"/>
	</bean>
	 <bean id="sqlSessionFactoryMifi" class="org.mybatis.spring.SqlSessionFactoryBean">
		<property name="dataSource" ref="dataSourceMifi"/>
		<property name="mapperLocations" value="classpath*:com/mifi/mapper/*.xml" />
	</bean>
	
	 <!-- mififlow -->
	<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
		<property name="basePackage" value="com.mififlow.dao" />
		<property name="sqlSessionFactory" ref="sqlSessionFactoryMifiFlow"/>
	</bean> 
	<bean id="sqlSessionFactoryMifiFlow" class="org.mybatis.spring.SqlSessionFactoryBean">
		<property name="dataSource" ref="dataSourceMifiFlow"/>
		<property name="mapperLocations" value="classpath*:com/mififlow/mapper/*.xml" />
	</bean>
	
	 <!-- mifidb -->
	<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
		<property name="basePackage" value="com.mifidb.dao" />
		<property name="sqlSessionFactory" ref="sqlSessionFactoryMifiDb"/>
	</bean> 
	<bean id="sqlSessionFactoryMifiDb" class="org.mybatis.spring.SqlSessionFactoryBean">
		<property name="dataSource" ref="dataSourceMifiDb"/>
		<property name="mapperLocations" value="classpath*:com/mifidb/mapper/*.xml" />
	</bean>
	
</beans>   

 

 

 

package com.mifi.bean;

import java.io.Serializable;
import java.sql.Timestamp;
 
 

public class MifiDevice implements Serializable{
 
	private static final long serialVersionUID = -2696646267915239503L;
	//	id,device_mode,device_type,device_mac,device_no,device_code,device_ip,surplus_flow,create_time,modify_time,status
	 private long id;
	 private String deviceMode;
	 private String deviceType;
	 private String deviceMac;
	 private String deviceNo;
	 private String deviceCode;
	 private String deviceIp;
	 private long surplusFlow;
	 private Timestamp createTime;
	 private Timestamp modifyTime;
	 private int status;
	 
	 
	public long getId() {
		return id;
	}
	public String getDeviceMode() {
		return deviceMode;
	}
	public String getDeviceType() {
		return deviceType;
	}
	public String getDeviceMac() {
		return deviceMac;
	}
	public String getDeviceNo() {
		return deviceNo;
	}
	public String getDeviceCode() {
		return deviceCode;
	}
	public String getDeviceIp() {
		return deviceIp;
	}
	public long getSurplusFlow() {
		return surplusFlow;
	}
	public Timestamp getCreateTime() {
		return  createTime;
	}
	public Timestamp getModifyTime() {
		return modifyTime;
	}
	public int getStatus() {
		return status;
	}
	public void setId(long id) {
		this.id = id;
	}
	public void setDeviceMode(String deviceMode) {
		this.deviceMode = deviceMode;
	}
	public void setDeviceType(String deviceType) {
		this.deviceType = deviceType;
	}
	public void setDeviceMac(String deviceMac) {
		this.deviceMac = deviceMac;
	}
	public void setDeviceNo(String deviceNo) {
		this.deviceNo = deviceNo;
	}
	public void setDeviceCode(String deviceCode) {
		this.deviceCode = deviceCode;
	}
	public void setDeviceIp(String deviceIp) {
		this.deviceIp = deviceIp;
	}
	public void setSurplusFlow(long surplusFlow) {
		this.surplusFlow = surplusFlow;
	}
	public void setCreateTime(Timestamp createTime) {
		this.createTime = createTime;
	}
	public void setModifyTime(Timestamp modifyTime) {
		this.modifyTime = modifyTime;
	}
	public void setStatus(int status) {
		this.status = status;
	}
}

 

package com.mifi.dao;

import java.util.List;

import com.mifi.bean.MifiDevice;
 

public interface MifiDeviceDao {
  
	 public  MifiDevice  getMifiDeviceById(long id);
	 public List<MifiDevice> findAllMifiDevices(); 
	 public void addMifiDevice(MifiDevice mifiDevice);
	 public void delMifiDeviceById(long id);
	 public void updateMifiDevice(MifiDevice mifiDevice);
	 
}

 

<?xml version="1.0" encoding="UTF-8"?>    
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.mifi.dao.MifiDeviceDao">
 
    <!-- id,device_mode,device_type,device_mac,device_no,device_code,device_ip,surplus_flow,create_time,modify_time,status -->
    
    <!-- Result Map-->  
    <resultMap type="com.mifi.bean.MifiDevice" id="mifiDevice">   
        <result property="id" column="id"   javaType="long" jdbcType="INTEGER" />  
        <result property="deviceMode" column="device_mode" javaType="string" jdbcType="VARCHAR"/>  
        <result property="deviceType" column="device_type" javaType="string" jdbcType="VARCHAR"/>  
        <result property="deviceMac" column="device_mac" javaType="string" jdbcType="VARCHAR"/>  
        <result property="deviceNo" column="device_no" javaType="string" jdbcType="VARCHAR" />  
        <result property="deviceCode" column="device_code" javaType="string" jdbcType="VARCHAR"  />  
        <result property="deviceIp" column="device_ip" javaType="string" jdbcType="VARCHAR" />  
        <result property="surplusFlow" column="surplus_flow"   javaType="long" jdbcType="INTEGER" />  
        <result property="createTime" column="create_time"  jdbcType="TIMESTAMP"   javaType="java.sql.Timestamp" />  
        <result property="modifyTime" column="modify_time"   jdbcType="TIMESTAMP"   javaType="java.sql.Timestamp" />  
        <result property="status" column="status"    javaType="int" jdbcType="INTEGER" />   
     </resultMap>  
    

	<select id="getMifiDeviceById" resultMap="mifiDevice" parameterType="java.lang.Long">
		select * from mifi_device where id = #{id,jdbcType=INTEGER}
	</select>

	<select id="findAllMifiDevices" resultMap="mifiDevice">
		select * from mifi_device
	</select>

	<insert id="addMifiDevice" parameterType="com.mifi.bean.MifiDevice">
		INSERT INTO mifi_device
		(id,device_mode,device_type,device_mac,device_no,device_code,device_ip,surplus_flow,create_time,modify_time,status)
		VALUE
		(null,#{deviceMode},#{deviceType},#{deviceMac},#{deviceNo},#{deviceCode},#{deviceIp},#{surplusFlow},#{createTime},#{modifyTime},#{status})
	</insert>

	<delete id="delMifiDeviceById" parameterType="java.lang.Long">
		delete from mifi_device where id = #{id}
	</delete>

	<update id="updateMifiDevice" parameterType="com.mifi.bean.MifiDevice">
		update mifi_device
		<set>
			<if test="deviceMode != null ">device_mode = #{deviceMode},</if>
			<if test="deviceType != null ">device_type = #{deviceType},</if>
			<if test="deviceMac != null ">device_mac = #{deviceMac},</if>
			<if test="deviceNo != null ">device_no = #{deviceNo},</if>
			<if test="deviceCode != null ">device_code = #{deviceCode},</if>
			<if test="deviceIp != null ">device_ip = #{deviceIp},</if>
			<if test="surplusFlow != null ">surplus_flow = #{surplusFlow,jdbcType=INTEGER},</if>
			<if test="createTime != null ">create_time = #{createTime,jdbcType=TIMESTAMP},</if>
			<if test="modifyTime != null ">modify_time = #{modifyTime,jdbcType=TIMESTAMP},</if>
			<if test="status != null ">status = #{status,jdbcType=INTEGER}</if>
		</set>
		where id = #{id,jdbcType=INTEGER}
	</update>

</mapper>   

 

package com.mifi.service;

import java.util.List; 

import com.mifi.bean.MifiDevice; 


public interface MifiDeviceService {

	public  boolean  hasMifiDeviceById(long id); 
	public  MifiDevice  getMifiDeviceById(long id); 
	 public List<MifiDevice> findAllMifiDevices(); 
	 public void addMifiDevice(MifiDevice mifiDevice);
	 public void delMifiDeviceById(long id); 
	 public void updateMifiDevice(MifiDevice mifiDevice);
}

 

package com.mifi.serviceimpl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.mifi.bean.MifiDevice;
import com.mifi.dao.MifiDeviceDao;
import com.mifi.service.MifiDeviceService;
import com.netty.service.NettyServerService;

@NettyServerService(name="mifiDeviceService")
@Service
public class MifiDeviceServiceImpl implements MifiDeviceService {

	@Autowired
	MifiDeviceDao dao;
	
	public  boolean  hasMifiDeviceById(long id){
		return dao.getMifiDeviceById(id) == null ? false : true ;
	}
	
	public  MifiDevice  getMifiDeviceById(long id){
		return dao.getMifiDeviceById(id);
	}
	
	 public List<MifiDevice> findAllMifiDevices(){
		 return dao.findAllMifiDevices();
	 } 
	 
	 public void addMifiDevice(MifiDevice mifiDevice){
		 dao.addMifiDevice(mifiDevice);
	 }
	 
	 public void delMifiDeviceById(long id){
		 dao.delMifiDeviceById(id);
	 }
	 
	 public void updateMifiDevice(MifiDevice mifiDevice){
		 dao.updateMifiDevice(mifiDevice);
	 }
	
}

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

捐助开发者

在兴趣的驱动下,写一个免费的东西,有欣喜,也还有汗水,希望你喜欢我的作品,同时也能支持一下。 当然,有钱捧个钱场(右上角的爱心标志,支持支付宝和PayPal捐助),没钱捧个人场,谢谢各位。



 
 
 谢谢您的赞助,我会做的更好!

 

 

相关实践学习
每个IT人都想学的“Web应用上云经典架构”实战
本实验从Web应用上云这个最基本的、最普遍的需求出发,帮助IT从业者们通过“阿里云Web应用上云解决方案”,了解一个企业级Web应用上云的常见架构,了解如何构建一个高可用、可扩展的企业级应用架构。
MySQL数据库入门学习
本课程通过最流行的开源数据库MySQL带你了解数据库的世界。 &nbsp; 相关的阿里云产品:云数据库RDS MySQL 版 阿里云关系型数据库RDS(Relational Database Service)是一种稳定可靠、可弹性伸缩的在线数据库服务,提供容灾、备份、恢复、迁移等方面的全套解决方案,彻底解决数据库运维的烦恼。 了解产品详情:&nbsp;https://www.aliyun.com/product/rds/mysql&nbsp;
目录
相关文章
|
8月前
|
XML Java 数据库连接
微服务——SpringBoot使用归纳——Spring Boot集成MyBatis——基于 xml 的整合
本教程介绍了基于XML的MyBatis整合方式。首先在`application.yml`中配置XML路径,如`classpath:mapper/*.xml`,然后创建`UserMapper.xml`文件定义SQL映射,包括`resultMap`和查询语句。通过设置`namespace`关联Mapper接口,实现如`getUserByName`的方法。Controller层调用Service完成测试,访问`/getUserByName/{name}`即可返回用户信息。为简化Mapper扫描,推荐在Spring Boot启动类用`@MapperScan`注解指定包路径避免逐个添加`@Mapper`
405 0
|
5月前
|
Java 数据库连接 数据库
Spring boot 使用mybatis generator 自动生成代码插件
本文介绍了在Spring Boot项目中使用MyBatis Generator插件自动生成代码的详细步骤。首先创建一个新的Spring Boot项目,接着引入MyBatis Generator插件并配置`pom.xml`文件。然后删除默认的`application.properties`文件,创建`application.yml`进行相关配置,如设置Mapper路径和实体类包名。重点在于配置`generatorConfig.xml`文件,包括数据库驱动、连接信息、生成模型、映射文件及DAO的包名和位置。最后通过IDE配置运行插件生成代码,并在主类添加`@MapperScan`注解完成整合
892 1
Spring boot 使用mybatis generator 自动生成代码插件
|
5月前
|
Java 数据库连接 API
Java 对象模型现代化实践 基于 Spring Boot 与 MyBatis Plus 的实现方案深度解析
本文介绍了基于Spring Boot与MyBatis-Plus的Java对象模型现代化实践方案。采用Spring Boot 3.1.2作为基础框架,结合MyBatis-Plus 3.5.3.1进行数据访问层实现,使用Lombok简化PO对象,MapStruct处理对象转换。文章详细讲解了数据库设计、PO对象实现、DAO层构建、业务逻辑封装以及DTO/VO转换等核心环节,提供了一个完整的现代化Java对象模型实现案例。通过分层设计和对象转换,实现了业务逻辑与数据访问的解耦,提高了代码的可维护性和扩展性。
205 1
|
4月前
|
SQL Java 数据库连接
Spring、SpringMVC 与 MyBatis 核心知识点解析
我梳理的这些内容,涵盖了 Spring、SpringMVC 和 MyBatis 的核心知识点。 在 Spring 中,我了解到 IOC 是控制反转,把对象控制权交容器;DI 是依赖注入,有三种实现方式。Bean 有五种作用域,单例 bean 的线程安全问题及自动装配方式也清晰了。事务基于数据库和 AOP,有失效场景和七种传播行为。AOP 是面向切面编程,动态代理有 JDK 和 CGLIB 两种。 SpringMVC 的 11 步执行流程我烂熟于心,还有那些常用注解的用法。 MyBatis 里,#{} 和 ${} 的区别很关键,获取主键、处理字段与属性名不匹配的方法也掌握了。多表查询、动态
144 0
|
5月前
|
SQL Java 数据库
解决Java Spring Boot应用中MyBatis-Plus查询问题的策略。
保持技能更新是侦探的重要素质。定期回顾最佳实践和新技术。比如,定期查看MyBatis-Plus的更新和社区的最佳做法,这样才能不断提升查询效率和性能。
208 1
|
6月前
|
druid Java 关系型数据库
Spring Boot与Druid升级解决方案
好的,我需要帮助用户解决他们遇到的数据库连接问题,并升级项目的依赖。首先,用户提供的错误信息是关于Spring Boot应用在初始化数据源时抛出的异常,具体是Druid连接池验证连接失败。同时,用户希望升级项目的依赖版本。
576 10
|
10月前
|
SQL Java 数据库连接
对Spring、SpringMVC、MyBatis框架的介绍与解释
Spring 框架提供了全面的基础设施支持,Spring MVC 专注于 Web 层的开发,而 MyBatis 则是一个高效的持久层框架。这三个框架结合使用,可以显著提升 Java 企业级应用的开发效率和质量。通过理解它们的核心特性和使用方法,开发者可以更好地构建和维护复杂的应用程序。
499 29
|
8月前
|
XML Java 数据库连接
微服务——SpringBoot使用归纳——Spring Boot集成MyBatis——基于注解的整合
本文介绍了Spring Boot集成MyBatis的两种方式:基于XML和注解的形式。重点讲解了注解方式,包括@Select、@Insert、@Update、@Delete等常用注解的使用方法,以及多参数时@Param注解的应用。同时,针对字段映射不一致的问题,提供了@Results和@ResultMap的解决方案。文章还提到实际项目中常结合XML与注解的优点,灵活使用两者以提高开发效率,并附带课程源码供下载学习。
645 0
|
8月前
|
Java 数据库连接 数据库
微服务——SpringBoot使用归纳——Spring Boot集成MyBatis——MyBatis 介绍和配置
本文介绍了Spring Boot集成MyBatis的方法,重点讲解基于注解的方式。首先简述MyBatis作为持久层框架的特点,接着说明集成时的依赖导入,包括`mybatis-spring-boot-starter`和MySQL连接器。随后详细展示了`properties.yml`配置文件的内容,涵盖数据库连接、驼峰命名规范及Mapper文件路径等关键设置,帮助开发者快速上手Spring Boot与MyBatis的整合开发。
1051 0
|
10月前
|
SQL Java 数据库连接
【潜意识Java】深入理解MyBatis的Mapper层,以及让数据访问更高效的详细分析
深入理解MyBatis的Mapper层,以及让数据访问更高效的详细分析
1469 1