读写分离
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