当前位置:   article > 正文

springboot集成ShardingSphere-jdbc_io.shardingsphere s

io.shardingsphere sharding-jdbc-spring-boot-s
ShardingSphere-jdbc版本:4.1.1
Mysql创建两个数据库

一、pom文件

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  4. <modelVersion>4.0.0</modelVersion>
  5. <parent>
  6. <groupId>org.springframework.boot</groupId>
  7. <artifactId>spring-boot-starter-parent</artifactId>
  8. <version>2.7.1</version>
  9. <relativePath/> <!-- lookup parent from repository -->
  10. </parent>
  11. <groupId>com.shardingsphere</groupId>
  12. <artifactId>demo</artifactId>
  13. <version>0.0.1-SNAPSHOT</version>
  14. <name>shardingsphere</name>
  15. <description>Demo project for Spring Boot</description>
  16. <properties>
  17. <java.version>1.8</java.version>
  18. </properties>
  19. <dependencies>
  20. <dependency>
  21. <groupId>org.springframework.boot</groupId>
  22. <artifactId>spring-boot-starter-web</artifactId>
  23. </dependency>
  24. <!-- mysql -->
  25. <dependency>
  26. <groupId>mysql</groupId>
  27. <artifactId>mysql-connector-java</artifactId>
  28. </dependency>
  29. <!-- druid -->
  30. <dependency>
  31. <groupId>com.alibaba</groupId>
  32. <artifactId>druid</artifactId>
  33. <version>1.2.6</version>
  34. </dependency>
  35. <!-- mybatis-plus -->
  36. <dependency>
  37. <groupId>com.baomidou</groupId>
  38. <artifactId>mybatis-plus-boot-starter</artifactId>
  39. <version>3.4.0</version>
  40. </dependency>
  41. <!-- sharding-jdbc -->
  42. <dependency>
  43. <groupId>org.apache.shardingsphere</groupId>
  44. <artifactId>sharding-jdbc-spring-boot-starter</artifactId>
  45. <version>4.1.1</version>
  46. </dependency>
  47. <dependency>
  48. <groupId>io.shardingsphere</groupId>
  49. <artifactId>sharding-transaction-2pc-xa</artifactId>
  50. <version>3.1.0</version>
  51. </dependency>
  52. <dependency>
  53. <groupId>org.apache.shardingsphere</groupId>
  54. <artifactId>sharding-transaction-xa-core</artifactId>
  55. <version>4.1.1</version>
  56. </dependency>
  57. <dependency>
  58. <groupId>org.projectlombok</groupId>
  59. <artifactId>lombok</artifactId>
  60. <optional>true</optional>
  61. </dependency>
  62. <dependency>
  63. <groupId>org.springframework.boot</groupId>
  64. <artifactId>spring-boot-starter-test</artifactId>
  65. <scope>test</scope>
  66. </dependency>
  67. <dependency>
  68. <groupId>cn.hutool</groupId>
  69. <artifactId>hutool-all</artifactId>
  70. <version>5.5.8</version>
  71. </dependency>
  72. </dependencies>
  73. <build>
  74. <plugins>
  75. <plugin>
  76. <groupId>org.springframework.boot</groupId>
  77. <artifactId>spring-boot-maven-plugin</artifactId>
  78. </plugin>
  79. </plugins>
  80. </build>
  81. </project>

二、application.yml

  1. server:
  2. port: 8091
  3. spring:
  4. shardingsphere:
  5. datasource:
  6. names: ds-0,ds-1
  7. ds-0:
  8. url: jdbc:mysql://127.0.0.1:3306/ds-0?useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT%2B8&useSSL=false&useInformationSchema=false&allowPublicKeyRetrieval=true
  9. driver-class-name: com.mysql.cj.jdbc.Driver
  10. type: com.alibaba.druid.pool.DruidDataSource
  11. username: root
  12. password: 123456
  13. ds-1:
  14. url: jdbc:mysql://127.0.0.1:3306/ds-1?useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT%2B8&useSSL=false&useInformationSchema=false&allowPublicKeyRetrieval=true
  15. driver-class-name: com.mysql.cj.jdbc.Driver
  16. type: com.alibaba.druid.pool.DruidDataSource
  17. username: root
  18. password: 123456
  19. sharding:
  20. tables:
  21. user:
  22. # 数据节点配置,采用Groovy表达式
  23. actual-data-nodes: ds-$->{0..1}.user
  24. database-strategy:
  25. standard:
  26. sharding-column: age
  27. precise-algorithm-class-name: com.shardingsphere.algorithm.DefaultModuloPreciseShardingAlgorithm
  28. key-generator:
  29. column: id
  30. type: SNOWFLAKE
  31. props:
  32. worker.id: 11
  33. executor.size: 4
  34. max.connections.size.per.query: 1
  35. check.table.metadata.enabled: false
  36. message:
  37. actual-data-nodes: ds-$->{0..1}.message_$->{0..1}
  38. database-strategy:
  39. standard:
  40. sharding-column: contact_id
  41. precise-algorithm-class-name: com.shardingsphere.algorithm.DefaultModuloPreciseShardingAlgorithm
  42. table-strategy:
  43. standard:
  44. sharding-column: msg_id
  45. precise-algorithm-class-name: com.shardingsphere.algorithm.DefaultModuloPreciseShardingAlgorithm
  46. key-generator:
  47. column: msg_id
  48. type: SNOWFLAKE
  49. props:
  50. worker.id: 22
  51. executor.size: 4
  52. max.connections.size.per.query: 1
  53. check.table.metadata.enabled: false
  54. props:
  55. # 日志显示具体的SQL
  56. sql.show: true
  57. jta:
  58. atomikos:
  59. properties:
  60. max-actives: -1
  61. log-base-dir: ./logs/shardingsphere

yml文件会爆红,不影响项目启动。

分库分表规则:

1、读写分离

2、数据库垂直分片

3、水平分片:(1)数据库分片 ;(2) 水平分表

yml文件中采用的是数据库分片。

三、业务代码

1、src/main/java/com/shardingsphere/algorithm

分片策略

​​​​​​​

1、标准分片策略

标准分片策略适用于单分片键,此策略支持 PreciseShardingAlgorithm 和 RangeShardingAlgorithm 两个分片算法。

其中 PreciseShardingAlgorithm 是必选的,用于处理 = 和 IN 的分片。RangeShardingAlgorithm 是可选的,用于处理BETWEEN AND, >, <,>=,<= 条件分片,如果不配置RangeShardingAlgorithm,SQL中的条件等将按照全库路由处理。

2、复合分片策略

复合分片策略,同样支持对 SQL语句中的 =,>, <, >=, <=,IN和 BETWEEN AND 的分片操作。不同的是它支持多分片键,具体分配片细节完全由应用开发者实现。

3、行表达式分片策略

行表达式分片策略,支持对 SQL语句中的 = 和 IN 的分片操作,但只支持单分片键。这种策略通常用于简单的分片,不需要自定义分片算法,可以直接在配置文件中接着写规则。

t_order_$->{t_order_id % 4} 代表 t_order 对其字段 t_order_id取模,拆分成4张表,而表名分别是t_order_0 到 t_order_3。

4、Hint分片策略

Hint分片策略,对应上边的Hint分片算法,通过指定分片健而非从 SQL中提取分片健的方式进行分片的策略。

分片算法

1、精确分片算法

精确分片算法(PreciseShardingAlgorithm)用于单个字段作为分片键,SQL中有 = 与 IN 等条件的分片,需要在标准分片策略(StandardShardingStrategy )下使用。

2、范围分片算法

范围分片算法(RangeShardingAlgorithm)用于单个字段作为分片键,SQL中有 BETWEEN AND、>、<、>=、<=  等条件的分片,需要在标准分片策略(StandardShardingStrategy )下使用。

3、复合分片算法

复合分片算法(ComplexKeysShardingAlgorithm)用于多个字段作为分片键的分片操作,同时获取到多个分片健的值,根据多个字段处理业务逻辑。需要在复合分片策略(ComplexShardingStrategy )下使用。

4、Hint分片算法

Hint分片算法(HintShardingAlgorithm)稍有不同,上边的算法中都是解析SQL 语句提取分片键,并设置分片策略进行分片。但有些时候并没有使用任何的分片键和分片策略,可还想将 SQL 路由到目标数据库和表,就需要通过手动干预指定SQL的目标数据库和表信息,这也叫强制路由。

参考:分片算法和分片策略​​​​​​​

  1. package com.shardingsphere.algorithm;
  2. import org.apache.shardingsphere.api.sharding.complex.ComplexKeysShardingAlgorithm;
  3. import org.apache.shardingsphere.api.sharding.complex.ComplexKeysShardingValue;
  4. import java.util.Collection;
  5. /**
  6. * 复合分片算法
  7. * 用于多个字段作为分片键的分片操作,同时获取到多个分片健的值,根据多个字段处理业务逻辑。需要在复合分片策略下使用
  8. */
  9. public class DefaultComplexKeysShardingAlgorithm implements ComplexKeysShardingAlgorithm<Long> {
  10. @Override
  11. public Collection<String> doSharding(Collection<String> availableTargetNames, ComplexKeysShardingValue<Long> shardingValue) {
  12. // 多片键的精确值场景
  13. shardingValue.getColumnNameAndShardingValuesMap();
  14. // 多片键的范围值场景
  15. shardingValue.getColumnNameAndRangeValuesMap();
  16. // 根据以上两种情况来筛选数据节点: 数据源、物理表...
  17. return availableTargetNames;
  18. }
  19. }
  1. package com.shardingsphere.algorithm;
  2. import org.apache.shardingsphere.api.sharding.hint.HintShardingAlgorithm;
  3. import org.apache.shardingsphere.api.sharding.hint.HintShardingValue;
  4. import java.util.Collection;
  5. import java.util.LinkedHashSet;
  6. /**
  7. * Hint分片算法
  8. * 指定的外部路由值来筛选目标库、表,由外部指定分片信息,让 SQL在指定的分库、分表中执行
  9. */
  10. public class DefaultHintShardingAlgorithm implements HintShardingAlgorithm<Long> {
  11. @Override
  12. public Collection<String> doSharding(Collection<String> availableTargetNames, HintShardingValue<Long> shardingValue) {
  13. Collection<String> result = new LinkedHashSet<>();
  14. for (String each : availableTargetNames) {
  15. for (Long value : shardingValue.getValues()) {
  16. if (each.endsWith(String.valueOf(value))) {
  17. result.add(each);
  18. }
  19. }
  20. }
  21. return result;
  22. }
  23. }
  1. package com.shardingsphere.algorithm;
  2. import org.apache.shardingsphere.api.sharding.standard.PreciseShardingAlgorithm;
  3. import org.apache.shardingsphere.api.sharding.standard.PreciseShardingValue;
  4. import java.util.Collection;
  5. /**
  6. * 精确分片算法
  7. * 只支持对单个分片键(字段)为依据的分库分表,用于 SQL 含有 = 和 IN 的分片处理
  8. */
  9. public class DefaultModuloPreciseShardingAlgorithm implements PreciseShardingAlgorithm<Long> {
  10. @Override
  11. public String doSharding(Collection<String> availableTargetNames, PreciseShardingValue<Long> shardingValue) {
  12. String modulo = String.valueOf(shardingValue.getValue() % availableTargetNames.size());
  13. for (String targetName : availableTargetNames) {
  14. if (targetName.endsWith(modulo)) return targetName;
  15. }
  16. throw new UnsupportedOperationException();
  17. }
  18. }
  1. package com.shardingsphere.algorithm;
  2. import org.apache.shardingsphere.api.sharding.standard.RangeShardingAlgorithm;
  3. import org.apache.shardingsphere.api.sharding.standard.RangeShardingValue;
  4. import java.util.Collection;
  5. import java.util.LinkedHashSet;
  6. import java.util.stream.Collectors;
  7. /**
  8. * 范围分片算法
  9. * 标准分片策略只支持对单个分片键(字段)为依据的分库分表,
  10. * 范围分片:处理含有 >,>=, <=,<,=,IN 和BETWEEN AND操作符 的分片处理
  11. */
  12. public class DefaultModuloRangeShardingAlgorithm implements RangeShardingAlgorithm<Long> {
  13. @Override
  14. public Collection<String> doSharding(Collection<String> availableTargetNames, RangeShardingValue<Long> shardingValue) {
  15. Long lower = shardingValue.getValueRange().lowerEndpoint();
  16. Long upper = shardingValue.getValueRange().upperEndpoint();
  17. Collection<String> result = new LinkedHashSet<>();
  18. for (Long i = lower; i <= upper; i++) {
  19. if (result.size() == availableTargetNames.size()) break;
  20. String modulo = String.valueOf(i % availableTargetNames.size());
  21. result.addAll(availableTargetNames.stream().filter(m -> m.endsWith(modulo)).collect(Collectors.toList()));
  22. }
  23. return result;
  24. }
  25. }

2、src/main/java/com/shardingsphere/config

  1. package com.shardingsphere.config;
  2. import com.baomidou.mybatisplus.annotation.DbType;
  3. import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
  4. import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
  5. import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
  6. import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
  7. import com.shardingsphere.entity.Entity;
  8. import org.apache.ibatis.reflection.MetaObject;
  9. import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
  10. import org.springframework.context.annotation.Bean;
  11. import org.springframework.context.annotation.Configuration;
  12. import java.util.Calendar;
  13. @Configuration
  14. @ConditionalOnClass(value = {PaginationInterceptor.class})
  15. public class MyBatisPlusConfig implements MetaObjectHandler {
  16. /**
  17. * 创建时间
  18. *
  19. * @param metaObject
  20. */
  21. @Override
  22. public void insertFill(MetaObject metaObject) {
  23. if (metaObject.getOriginalObject() instanceof Entity) {
  24. Entity entity = (Entity) metaObject.getOriginalObject();
  25. if (entity.getCreationTime() == null) {
  26. this.setFieldValByName(Entity.META_CREATED, Calendar.getInstance().getTime(), metaObject);
  27. }
  28. }
  29. }
  30. /**
  31. * 更新时间
  32. *
  33. * @param metaObject
  34. */
  35. @Override
  36. public void updateFill(MetaObject metaObject) {
  37. if (metaObject.getOriginalObject() instanceof Entity) {
  38. Entity entity = (Entity) metaObject.getOriginalObject();
  39. if (entity.getUpdateTime() == null) {
  40. this.setFieldValByName(Entity.META_UPDATE, Calendar.getInstance().getTime(), metaObject);
  41. }
  42. }
  43. }
  44. /**
  45. * 分页
  46. *
  47. * @return
  48. */
  49. @Bean
  50. public MybatisPlusInterceptor mybatisPlusInterceptor() {
  51. MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
  52. interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
  53. return interceptor;
  54. }
  55. }
  1. package com.shardingsphere.config;
  2. import org.springframework.beans.factory.annotation.Qualifier;
  3. import org.springframework.context.annotation.Bean;
  4. import org.springframework.context.annotation.Configuration;
  5. import org.springframework.jdbc.core.JdbcTemplate;
  6. import org.springframework.jdbc.datasource.DataSourceTransactionManager;
  7. import org.springframework.transaction.PlatformTransactionManager;
  8. import org.springframework.transaction.annotation.EnableTransactionManagement;
  9. import javax.sql.DataSource;
  10. @Configuration
  11. @EnableTransactionManagement
  12. public class TransactionConfig {
  13. /**
  14. * 关联 datasource 到 spring 的 PlatformTransactionManager(没有直接使用 jdbc 原生事务)
  15. */
  16. @Bean
  17. public PlatformTransactionManager txManager(@Qualifier("shardingDataSource") final DataSource dataSource) {
  18. return new DataSourceTransactionManager(dataSource);
  19. }
  20. /**
  21. * 通过 jdbcTemplate 简化原生 sharding-jdbc SQL 的使用
  22. */
  23. @Bean
  24. public JdbcTemplate jdbcTemplate(@Qualifier("shardingDataSource") final DataSource dataSource) {
  25. return new JdbcTemplate(dataSource);
  26. }
  27. }

3、src/main/java/com/shardingsphere/controller

  1. package com.shardingsphere.controller;
  2. import com.shardingsphere.service.MessageService;
  3. import org.springframework.beans.factory.annotation.Autowired;
  4. import org.springframework.web.bind.annotation.PostMapping;
  5. import org.springframework.web.bind.annotation.RequestMapping;
  6. import org.springframework.web.bind.annotation.RestController;
  7. @RestController
  8. @RequestMapping("/user")
  9. public class UserController {
  10. @Autowired
  11. private MessageService messageService;
  12. @PostMapping("/add")
  13. public int add() {
  14. return messageService.add();
  15. }
  16. @PostMapping("/update")
  17. public int updateByName() {
  18. return messageService.updateByName();
  19. }
  20. }

4、src/main/java/com/shardingsphere/entity

  1. package com.shardingsphere.entity;
  2. import com.baomidou.mybatisplus.annotation.FieldFill;
  3. import com.baomidou.mybatisplus.annotation.TableField;
  4. import com.baomidou.mybatisplus.extension.activerecord.Model;
  5. import java.util.Date;
  6. public class Entity<T extends Entity<?>> extends Model<T> {
  7. public final static String META_CREATED = "creationTime";
  8. public final static String META_UPDATE = "updateTime";
  9. @TableField(fill = FieldFill.INSERT)
  10. private Date creationTime;
  11. @TableField(fill = FieldFill.UPDATE)
  12. private Date updateTime;
  13. public Date getCreationTime() {
  14. return creationTime;
  15. }
  16. public void setCreationTime(Date creationTime) {
  17. this.creationTime = creationTime;
  18. }
  19. public Date getUpdateTime() {
  20. return updateTime;
  21. }
  22. public void setUpdateTime(Date updateTime) {
  23. this.updateTime = updateTime;
  24. }
  25. }
  1. package com.shardingsphere.entity;
  2. import com.baomidou.mybatisplus.annotation.IdType;
  3. import com.baomidou.mybatisplus.annotation.TableId;
  4. import com.baomidou.mybatisplus.annotation.TableName;
  5. import com.fasterxml.jackson.annotation.JsonFormat;
  6. import lombok.Data;
  7. import java.io.Serializable;
  8. import java.util.Date;
  9. @Data
  10. @TableName("t_message")
  11. public class Message implements Serializable {
  12. private static final long serialVersionUID = 2921554930924807501L;
  13. @TableId(type = IdType.ASSIGN_ID)
  14. private Long msgId;
  15. private Long contactId;
  16. private Long userId;
  17. private Boolean userTag;
  18. private Date recallTime;
  19. private String content;
  20. private String pushMsg;
  21. @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
  22. private Date creationTime;
  23. }
  1. package com.shardingsphere.entity;
  2. import com.baomidou.mybatisplus.annotation.IdType;
  3. import com.baomidou.mybatisplus.annotation.TableId;
  4. import com.baomidou.mybatisplus.annotation.TableName;
  5. import lombok.Data;
  6. import java.io.Serializable;
  7. @Data
  8. @TableName("t_user")
  9. public class User extends Entity<User> implements Serializable {
  10. private static final long serialVersionUID = -94704944729049233L;
  11. @TableId(type = IdType.ASSIGN_ID)
  12. private Long id;
  13. private String name;
  14. private Long age;
  15. private String sex;
  16. private String education;
  17. }

5、src/main/java/com/shardingsphere/Mapper

  1. package com.shardingsphere.Mapper;
  2. import com.baomidou.mybatisplus.core.mapper.BaseMapper;
  3. import com.shardingsphere.entity.Message;
  4. import org.apache.ibatis.annotations.Mapper;
  5. import org.springframework.stereotype.Repository;
  6. @Mapper
  7. @Repository
  8. public interface MessageMapper extends BaseMapper<Message> {
  9. }
  1. package com.shardingsphere.Mapper;
  2. import com.baomidou.mybatisplus.core.mapper.BaseMapper;
  3. import com.shardingsphere.entity.User;
  4. import org.apache.ibatis.annotations.Mapper;
  5. import org.springframework.stereotype.Repository;
  6. @Mapper
  7. @Repository
  8. public interface UserMapper extends BaseMapper<User> {
  9. }

6、src/main/java/com/shardingsphere/service

  1. package com.shardingsphere.service;
  2. import com.baomidou.mybatisplus.extension.service.IService;
  3. import com.shardingsphere.entity.Message;
  4. public interface MessageService extends IService<Message> {
  5. int add();
  6. int updateByName();
  7. }
  1. package com.shardingsphere.service.impl;
  2. import cn.hutool.core.lang.Snowflake;
  3. import cn.hutool.core.util.IdUtil;
  4. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  5. import com.baomidou.mybatisplus.core.mapper.Mapper;
  6. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  7. import com.shardingsphere.Mapper.MessageMapper;
  8. import com.shardingsphere.Mapper.UserMapper;
  9. import com.shardingsphere.entity.Message;
  10. import com.shardingsphere.entity.User;
  11. import com.shardingsphere.service.MessageService;
  12. import org.apache.shardingsphere.transaction.annotation.ShardingTransactionType;
  13. import org.apache.shardingsphere.transaction.core.TransactionType;
  14. import org.springframework.beans.factory.annotation.Autowired;
  15. import org.springframework.stereotype.Service;
  16. import org.springframework.transaction.annotation.Transactional;
  17. import java.util.Date;
  18. @Service
  19. public class MessageServiceImpl extends ServiceImpl<MessageMapper, Message> implements MessageService {
  20. @Autowired
  21. private UserMapper userMapper;
  22. @Autowired
  23. private MessageMapper messageMapper;
  24. @Transactional(rollbackFor = Exception.class)
  25. @ShardingTransactionType(TransactionType.XA)
  26. @Override
  27. public int add() {
  28. Snowflake snowflake = IdUtil.createSnowflake(1, 1);
  29. Message message = new Message();
  30. int randomNum = (int) (Math.random() * 9000 + 1000);
  31. message.setMsgId(snowflake.nextId());
  32. message.setContactId(snowflake.nextId());
  33. message.setUserId(new Long(randomNum));
  34. message.setUserTag(Boolean.TRUE);
  35. message.setRecallTime(new Date());
  36. message.setContent("测试测试");
  37. message.setPushMsg("22225555");
  38. message.setCreationTime(new Date());
  39. messageMapper.insert(message);
  40. User user = new User();
  41. user.setName("李四");
  42. int randomNum2 = (int) (Math.random() * 9000 + 1000);
  43. user.setAge(new Long(randomNum2));
  44. user.setSex("2");
  45. user.setEducation("1");
  46. int insert = userMapper.insert(user);
  47. // if (insert > 0) {
  48. // //抛出异常 事务回滚
  49. // int a = 10 / 0;
  50. // return 1;
  51. // }
  52. return 0;
  53. }
  54. @Transactional(rollbackFor = Exception.class)
  55. @ShardingTransactionType(TransactionType.XA)
  56. @Override
  57. public int updateByName() {
  58. QueryWrapper<User> wrapper = new QueryWrapper<>();
  59. wrapper.lambda().eq(User::getName,"李四");
  60. User user = userMapper.selectOne(wrapper);
  61. user.setName("李四大大");
  62. int update = userMapper.updateById(user);
  63. return update;
  64. }
  65. }

四、数据库表

  1. SET NAMES utf8mb4;
  2. SET FOREIGN_KEY_CHECKS = 0;
  3. -- ----------------------------
  4. -- Table structure for t_user
  5. -- ----------------------------
  6. DROP TABLE IF EXISTS `t_user`;
  7. CREATE TABLE `t_user` (
  8. `id` bigint(0) NOT NULL,
  9. `name` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
  10. `age` bigint(0) NULL DEFAULT NULL,
  11. `sex` int(0) NOT NULL,
  12. `education` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  13. `creation_time` datetime(0) NULL DEFAULT NULL,
  14. `update_time` datetime(0) NULL DEFAULT NULL,
  15. PRIMARY KEY (`id`) USING BTREE
  16. ) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;
  17. SET FOREIGN_KEY_CHECKS = 1;
  1. SET NAMES utf8mb4;
  2. SET FOREIGN_KEY_CHECKS = 0;
  3. -- ----------------------------
  4. -- Table structure for t_message
  5. -- ----------------------------
  6. DROP TABLE IF EXISTS `t_message`;
  7. CREATE TABLE `t_message` (
  8. `msg_id` bigint(0) NOT NULL,
  9. `contact_id` bigint(0) NULL DEFAULT NULL,
  10. `user_id` bigint(0) NULL DEFAULT NULL,
  11. `user_tag` varchar(1) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  12. `recall_time` datetime(0) NULL DEFAULT NULL,
  13. `content` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  14. `push_msg` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  15. `creation_time` datetime(0) NULL DEFAULT NULL,
  16. PRIMARY KEY (`msg_id`) USING BTREE
  17. ) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;
  18. SET FOREIGN_KEY_CHECKS = 1;

五、测试

1、postman

2、插入数据库结果

 3、更新数据库内容自己测试。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/盐析白兔/article/detail/210936
推荐阅读
相关标签
  

闽ICP备14008679号