分库分表-----shardingsphere读写分离

读写分离

1:工具:idea,技术:springboot+shardingsphere+mybatis
2:新建asmaster0,asslave0,asmaster0为主表,进行写操作,asmaster0为从表,进行读操作,每个库中有一个user表

3:SQL语句,创建user表

CREATE TABLE user(
id INT(20) NOT NULL AUTO_INCREMENT,
NAME VARCHAR(30)  NOT NULL,
age INT(10) NOT NULL,
create_time DATETIME NOT NULL,
PRIMARY KEY(id) 
)

4:创建实体类

package com.bean;

import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;

import java.io.Serializable;
import java.util.Date;

@Data
public class User implements Serializable {
	private int id;
	private String name ;
	private String age;
	// 这行为显示给前台正常格式的语句
	@JsonFormat(pattern = "yyyy-MM-dd ",timezone = "GMT+8")
	//这行为前台请求后台时候,转换格式用的,因为前台传过来的字符串类型,而后台是date类型
	@DateTimeFormat(pattern = "yyyy-MM-dd")
	private Date create_time;
}

5: 创建mapper类

package com.mapper;

import com.bean.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
public interface UserMapper {

	/**
	 * 添加
	 */
	@I
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值