mirror of
https://github.com/201206030/novel-plus.git
synced 2025-06-24 04:46:37 +00:00
引入shardingjdbc,将小说内容表分为10个小表
This commit is contained in:
@ -24,7 +24,7 @@ public final class BookContentDynamicSqlSupport {
|
||||
|
||||
public final SqlColumn<Long> indexId = column("index_id", JDBCType.BIGINT);
|
||||
|
||||
public final SqlColumn<String> content = column("content", JDBCType.LONGVARCHAR);
|
||||
public final SqlColumn<String> content = column("content", JDBCType.VARCHAR);
|
||||
|
||||
public BookContent() {
|
||||
super("book_content");
|
||||
|
@ -63,7 +63,7 @@ public interface BookContentMapper {
|
||||
@Results(id="BookContentResult", value = {
|
||||
@Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true),
|
||||
@Result(column="index_id", property="indexId", jdbcType=JdbcType.BIGINT),
|
||||
@Result(column="content", property="content", jdbcType=JdbcType.LONGVARCHAR)
|
||||
@Result(column="content", property="content", jdbcType=JdbcType.VARCHAR)
|
||||
})
|
||||
List<BookContent> selectMany(SelectStatementProvider selectStatement);
|
||||
|
||||
|
@ -1,11 +1,57 @@
|
||||
spring:
|
||||
profiles:
|
||||
include: [common]
|
||||
datasource:
|
||||
url: jdbc:mysql://127.0.0.1:3306/novel_plus?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai
|
||||
username: root
|
||||
password: test123456
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
main:
|
||||
allow-bean-definition-overriding: true
|
||||
|
||||
# datasource:
|
||||
# url: jdbc:mysql://127.0.0.1:3306/novel_plus?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai
|
||||
# username: root
|
||||
# password: test123456
|
||||
# driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
shardingsphere:
|
||||
datasource:
|
||||
names: master
|
||||
|
||||
|
||||
####使用shardingJdbc时,
|
||||
####所有的jdbcType都不能是LONGVARCHAR,否则会导致java.io.NotSerializableException: java.io.StringReader错误
|
||||
##### 应该替换所有的 LONGVARCHAR 类型为VARCHAR
|
||||
|
||||
sharding:
|
||||
jdbc:
|
||||
datasource:
|
||||
names: ds0 #,ds1
|
||||
ds0:
|
||||
type: com.zaxxer.hikari.HikariDataSource
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
jdbc-url: jdbc:mysql://localhost:3306/novel_plus?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai
|
||||
username: root
|
||||
password: test123456
|
||||
# ds1:
|
||||
# type: com.alibaba.druid.pool.DruidDataSource
|
||||
# driver-class-name: com.mysql.jdbc.Driver
|
||||
# url: jdbc:mysql://localhost:3306/novel_plus2
|
||||
# username: root
|
||||
# password: test123456
|
||||
config:
|
||||
sharding:
|
||||
props:
|
||||
sql.show: true
|
||||
tables:
|
||||
book_content: #book_content表
|
||||
key-generator-column-name: id #主键
|
||||
actual-data-nodes: ds${0}.book_content${0..9} #数据节点
|
||||
# database-strategy: #分库策略
|
||||
# inline:
|
||||
# sharding-column: book_id
|
||||
# algorithm-expression: ds${book_id % 10}
|
||||
table-strategy: #分表策略
|
||||
inline:
|
||||
shardingColumn: index_id
|
||||
algorithm-expression: book_content${index_id % 10}
|
||||
|
||||
|
||||
#Redis服务器IP
|
||||
redis:
|
||||
host: 127.0.0.1
|
||||
|
Reference in New Issue
Block a user