技术标签: spring boot java 中间件 后端
1.添加依赖pom
<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>sharding-jdbc-spring-boot-starter</artifactId>
<version>4.0.1</version>
</dependency>
2.User实体类
@Setter
@Getter
@AllArgsConstructor
@NoArgsConstructor
@ToString
public class User {
private String id;
private String name;
private Integer age;
}
3.建表语句,两张表分别为user_0,user_1
CREATE TABLE `user_0` (
`id` varchar(100) NOT NULL DEFAULT '',
`name` varchar(100) DEFAULT NULL,
`age` tinyint(3) unsigned DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
CREATE TABLE `user_1` (
`id` varchar(100) NOT NULL DEFAULT '',
`name` varchar(100) DEFAULT NULL,
`age` tinyint(3) unsigned DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
4.userMapper
@Mapper
public interface UserMapper {
@Select("select * from user")
List<User> selectAll();
@Delete("delete from user where id = #{id}")
int deleteById(String id);
@Insert("insert into user(name,age) values(#{user.name},#{user.age})")
int insert(@Param("user") User user);
}
5.userController
@Controller
@RequestMapping("/user")
@RequiredArgsConstructor
public class UserController {
private static User user = new User();
private final UserMapper userMapper;
@PostMapping("/insert")
@ResponseBody
public int insert(@RequestBody User user) {
return userMapper.insert(user);
}
}
6.配置文件application.properties
#配置数据源名称ds1,ds2
spring.shardingsphere.datasource.names=ds1,ds2
spring.shardingsphere.datasource.ds1.type=com.zaxxer.hikari.HikariDataSource
spring.shardingsphere.datasource.ds1.driver-class-name=com.mysql.jdbc.Driver
spring.shardingsphere.datasource.ds1.jdbc-url=jdbc:mysql://127.0.0.1:3306/sharding
spring.shardingsphere.datasource.ds1.username=root
spring.shardingsphere.datasource.ds1.password=root
spring.shardingsphere.datasource.ds2.type=com.zaxxer.hikari.HikariDataSource
spring.shardingsphere.datasource.ds2.driver-class-name=com.mysql.jdbc.Driver
spring.shardingsphere.datasource.ds2.jdbc-url=jdbc:mysql://127.0.0.1:3306/sharding2
spring.shardingsphere.datasource.ds2.username=root
spring.shardingsphere.datasource.ds2.password=root
spring.shardingsphere.sharding.tables.user.actual-data-nodes=ds1.user_$->{0..1}
#指定表中主键生成策略 SNOWFLAKE
spring.shardingsphere.sharding.tables.user.key-generator.column=id
spring.shardingsphere.sharding.tables.user.key-generator.type=SNOWFLAKE
#指定分片策略 约定id 偶数添加到user_0表 奇数添加到user_1表
spring.shardingsphere.sharding.tables.user.table-strategy.inline.sharding-column=id
spring.shardingsphere.sharding.tables.user.table-strategy.inline.algorithm-expression=user_$->{id % 2}
# 打开 sql 输出日志
spring.shardingsphere.props.sql.show=true
#一个实体类对应两张表,覆盖
#spring.main.allow-bean-definition-overriding=true
# 写库数据源名称
spring.shardingsphere.rules.readwrite-splitting.data-sources.readwrite_ds.static-strategy.write-data-source-name=ds1
# 读库数据源列表,多个从数据源用逗号分隔
spring.shardingsphere.rules.readwrite-splitting.data-sources.readwrite_ds.static-strategy.read-data-source-names=ds2
# 负载均衡算法名称
spring.shardingsphere.rules.readwrite-splitting.data-sources.readwrite_ds.load-balancer-name=round_robin
# 负载均衡算法配置
spring.shardingsphere.rules.readwrite-splitting.load-balancers.round_robin.type=ROUND_ROBIN
7.启动程序,调用插入接口会发现偶数id添加到user_0表,奇数id添加到user_1表
importpygameimportsysfrom pygame.sprite importSpritefrom pygame.sprite importGroupclassSettings():def __init__(self):self.screen_width= 1200self.screen_height= 800self.bg_color= (255,255,255)self.qian..._python快速编程入门第十三章飞机大战
一、 结构体回顾 C语言允许用户自己建立由不同类型数据组成的组合型的数据结构,就称为结构体(structre),在其他一些高级语言中称为“记录”(record)。结构体举例:struct S1 { long a; char b; int c; }; // 注意分号不能省略 那么我们如何判断这个结构体所占内存的大小呢??? 在32位机..._怎么确定结构体的大小
样式引入<link href="../../../js/ztree/zTreeStyle.css" rel="stylesheet" type="text/css" /><link rel="stylesheet" type="text/css" href="../../../js/ztree/css/metroStyle/metroStyle.css"><link rel="stylesheet" type="text/css" href="../../../js/_layui 树形下拉多选
简介本教程主要讲解如何实现由Leon A. Gatys,Alexander S. Ecker和Matthias Bethge提出的 Neural-Style 算法。Neural-Style或者叫Neural-Transfer,可以让你使用一种新的风格将指定的图片进行重构。这个算法使用三张图片,一张输入图片,一张内容图片和一张风格图片,并将输入的图片变得与内容图片相似,且拥有风格图片的优美风格。基本..._pytorch 图片转化为张量
当我们需要把库当脚本运行的时候,就需要使用python -m了。举个栗子:比如使用pytorch进行分布式开发的时候,可能会用到:python -m torch.distributed.launch --nproc_per_node 1 --master_port 12345 main.py --eval --cfg configs/swin_tiny_patch4_window7_224.yaml --resume models/swin_tiny_patch4_window7_224.pth --d_pycharm python -m
笔记:写python脚本(九宫格批量修改)之遍历文件mian函数的执行代码之一:↓↓↓↓↓↓↓ #第一步 picnamestr = raw_input(&amp;amp;amp;quot;please input picture name:&amp;amp;amp;quot;) searchpath = os.getcwd() print(&amp;amp;amp;quot;search path=&amp;amp
前言如果你还不知道ZKEACMS,不妨先了解一下。ASP.NET MVC 开源建站系统 ZKEACMS 推荐,从此网站“拼”起来官方地址:http://www.zkea.net/zkeacms下载地址:https://github.com/SeriaWei/ASP.NET-MVC-CMS/releasesGitHub:https://github.c
题目链接:https://www.patest.cn/contests/pat-b-practise/10201020. 月饼 (25)时间限制100 ms内存限制65536 kB代码长度限制8000 B判题程序Standard作者CHEN, Yue
errno.h定义了一个全局宏 errno1.在利用某些函数对文件进行操作时,有可能发生错误,若发生错误有可能对errno的值进行修改,此时可以利用errno的值与strerror(errno)相结合输出相应的错误信息,2.多个函数对文件进行操作时,都可能修改errno的值,所以若想得到错误信息,最好每执行完一个文件操作时,就输出strerror(errno)信息3.在并发系统中,er
深度学习时间序列预测:卷积神经网络(CNN)算法构建单变量时间序列预测模型预测空气质量(PM2.5)+代码实战神经网络(neual networks)是人工智能研究领域的一部分,当前最流行的神经网络是深度卷积神经网络(deep convolutional neural networks, CNNs),虽然卷积网络也存在浅层结构,但是因为准确度和表现力等原因很少使用。目前提到CNNs和卷积神经网络,学术界和工业界不再进行特意区分,一般都指深层结构的卷积神经网络,层数从”几层“到”几十上百“不定。C
1.技术点(1) 基础框架-ssm(SpringMVC+Spring+MyBatis) (2) 数据库-MySQL (3) 前端框架-bootstrap快速搭建简洁美观的界面 (4) 项目的依赖管理-Maven (5) 分页-pagehelper 插件(6) 逆向工程-MyBatis Generator2.基础环境搭建(1) 创建一个maven工程 (2) 引入项目依赖的jar...
mod_security官方的文档有一些问题,亲手装了一遍,现将问题记录如下Windows xampp版本假设xampp安装在D:/xampp1 下载mod_security-2.5.9-win32.zip,解压缩2 将libxml2.dll拷贝到D:/xampp/apache/bin下面3 将mod_security2.so拷贝到D:/xampp/apache/modu..._modsecurity配置xampp