init
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>blade-example</artifactId>
|
||||
<groupId>org.springblade</groupId>
|
||||
<version>${revision}</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>blade-sharding-jdbc</artifactId>
|
||||
<name>${project.artifactId}</name>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<dependencies>
|
||||
<!-- bladex -->
|
||||
<dependency>
|
||||
<groupId>org.springblade</groupId>
|
||||
<artifactId>blade-core-boot</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springblade</groupId>
|
||||
<artifactId>blade-starter-swagger</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springblade</groupId>
|
||||
<artifactId>blade-starter-tenant</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springblade</groupId>
|
||||
<artifactId>blade-starter-sharding</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springblade</groupId>
|
||||
<artifactId>blade-core-auto</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
/**
|
||||
* BladeX Commercial License Agreement
|
||||
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||
* <p>
|
||||
* Use of this software is governed by the Commercial License Agreement
|
||||
* obtained after purchasing a license from BladeX.
|
||||
* <p>
|
||||
* 1. This software is for development use only under a valid license
|
||||
* from BladeX.
|
||||
* <p>
|
||||
* 2. Redistribution of this software's source code to any third party
|
||||
* without a commercial license is strictly prohibited.
|
||||
* <p>
|
||||
* 3. Licensees may copyright their own code but cannot use segments
|
||||
* from this software for such purposes. Copyright of this software
|
||||
* remains with BladeX.
|
||||
* <p>
|
||||
* Using this software signifies agreement to this License, and the software
|
||||
* must not be used for illegal purposes.
|
||||
* <p>
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||
* not liable for any claims arising from secondary or illegal development.
|
||||
* <p>
|
||||
* Author: Chill Zhuang (bladejava@qq.com)
|
||||
*/
|
||||
package org.springblade.sharding;
|
||||
|
||||
import org.springblade.core.cloud.client.BladeCloudApplication;
|
||||
import org.springblade.core.launch.BladeApplication;
|
||||
|
||||
import static org.springblade.common.constant.LauncherConstant.APPLICATION_SHARDING_NAME;
|
||||
|
||||
/**
|
||||
* 启动器
|
||||
*
|
||||
* @author Chill
|
||||
*/
|
||||
@BladeCloudApplication
|
||||
public class ShardingApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
BladeApplication.run(APPLICATION_SHARDING_NAME, ShardingApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+150
@@ -0,0 +1,150 @@
|
||||
/**
|
||||
* BladeX Commercial License Agreement
|
||||
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||
* <p>
|
||||
* Use of this software is governed by the Commercial License Agreement
|
||||
* obtained after purchasing a license from BladeX.
|
||||
* <p>
|
||||
* 1. This software is for development use only under a valid license
|
||||
* from BladeX.
|
||||
* <p>
|
||||
* 2. Redistribution of this software's source code to any third party
|
||||
* without a commercial license is strictly prohibited.
|
||||
* <p>
|
||||
* 3. Licensees may copyright their own code but cannot use segments
|
||||
* from this software for such purposes. Copyright of this software
|
||||
* remains with BladeX.
|
||||
* <p>
|
||||
* Using this software signifies agreement to this License, and the software
|
||||
* must not be used for illegal purposes.
|
||||
* <p>
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||
* not liable for any claims arising from secondary or illegal development.
|
||||
* <p>
|
||||
* Author: Chill Zhuang (bladejava@qq.com)
|
||||
*/
|
||||
package org.springblade.sharding.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Parameters;
|
||||
import io.swagger.v3.oas.annotations.enums.ParameterIn;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springblade.core.boot.ctrl.BladeController;
|
||||
import org.springblade.core.mp.support.Condition;
|
||||
import org.springblade.core.mp.support.Query;
|
||||
import org.springblade.core.sharding.annotation.ShardingDS;
|
||||
import org.springblade.core.tool.api.R;
|
||||
import org.springblade.core.tool.utils.Func;
|
||||
import org.springblade.sharding.entity.Notice;
|
||||
import org.springblade.sharding.service.INoticeService;
|
||||
import org.springblade.sharding.vo.NoticeVO;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 控制器
|
||||
*
|
||||
* @author Chill
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("notice")
|
||||
@AllArgsConstructor
|
||||
@Tag(name = "通知公告", description = "通知公告接口")
|
||||
public class NoticeController extends BladeController {
|
||||
|
||||
private final INoticeService noticeService;
|
||||
|
||||
|
||||
/**
|
||||
* 新增或修改(使用sharding)
|
||||
*/
|
||||
@ShardingDS
|
||||
@PostMapping("/submit")
|
||||
@ApiOperationSupport(order = 1)
|
||||
@Operation(summary = "新增或修改", description = "传入notice")
|
||||
public R submit(@RequestBody Notice notice) {
|
||||
return R.status(noticeService.saveOrUpdate(notice));
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页(使用sharding)
|
||||
*/
|
||||
@ShardingDS
|
||||
@GetMapping("/list")
|
||||
@Parameters({
|
||||
@Parameter(name = "category", description = "公告类型", in = ParameterIn.QUERY, schema = @Schema(type = "integer")),
|
||||
@Parameter(name = "title", description = "公告标题", in = ParameterIn.QUERY, schema = @Schema(type = "string"))
|
||||
})
|
||||
@ApiOperationSupport(order = 2)
|
||||
@Operation(summary = "分页", description = "传入notice")
|
||||
public R<IPage<Notice>> list(@Parameter(hidden = true) @RequestParam Map<String, Object> notice, Query query) {
|
||||
IPage<Notice> pages = noticeService.page(Condition.getPage(query), Condition.getQueryWrapper(notice, Notice.class));
|
||||
return R.data(pages);
|
||||
}
|
||||
|
||||
/**
|
||||
* 多表联合查询自定义分页
|
||||
*/
|
||||
@GetMapping("/page")
|
||||
@Parameters({
|
||||
@Parameter(name = "category", description = "公告类型", in = ParameterIn.QUERY, schema = @Schema(type = "integer")),
|
||||
@Parameter(name = "title", description = "公告标题", in = ParameterIn.QUERY, schema = @Schema(type = "string"))
|
||||
})
|
||||
@ApiOperationSupport(order = 3)
|
||||
@Operation(summary = "分页", description = "传入notice")
|
||||
public R<IPage<NoticeVO>> page(@Parameter(hidden = true) NoticeVO notice, Query query) {
|
||||
IPage<NoticeVO> pages = noticeService.selectNoticePage(Condition.getPage(query), notice);
|
||||
return R.data(pages);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增
|
||||
*/
|
||||
@PostMapping("/save")
|
||||
@ApiOperationSupport(order = 4)
|
||||
@Operation(summary = "新增", description = "传入notice")
|
||||
public R save(@RequestBody Notice notice) {
|
||||
return R.status(noticeService.save(notice));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改
|
||||
*/
|
||||
@PostMapping("/update")
|
||||
@ApiOperationSupport(order = 5)
|
||||
@Operation(summary = "修改", description = "传入notice")
|
||||
public R update(@RequestBody Notice notice) {
|
||||
return R.status(noticeService.updateById(notice));
|
||||
}
|
||||
|
||||
/**
|
||||
* 详情
|
||||
*/
|
||||
@GetMapping("/detail")
|
||||
@ApiOperationSupport(order = 6)
|
||||
@Operation(summary = "详情", description = "传入notice")
|
||||
public R<Notice> detail(Notice notice) {
|
||||
Notice detail = noticeService.getOne(Condition.getQueryWrapper(notice));
|
||||
return R.data(detail);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
@ShardingDS
|
||||
@PostMapping("/remove")
|
||||
@ApiOperationSupport(order = 7)
|
||||
@Operation(summary = "逻辑删除", description = "传入notice")
|
||||
public R remove(@Parameter(name = "主键集合") @RequestParam String ids) {
|
||||
boolean temp = noticeService.deleteLogic(Func.toLongList(ids));
|
||||
return R.status(temp);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
+81
@@ -0,0 +1,81 @@
|
||||
/**
|
||||
* BladeX Commercial License Agreement
|
||||
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||
* <p>
|
||||
* Use of this software is governed by the Commercial License Agreement
|
||||
* obtained after purchasing a license from BladeX.
|
||||
* <p>
|
||||
* 1. This software is for development use only under a valid license
|
||||
* from BladeX.
|
||||
* <p>
|
||||
* 2. Redistribution of this software's source code to any third party
|
||||
* without a commercial license is strictly prohibited.
|
||||
* <p>
|
||||
* 3. Licensees may copyright their own code but cannot use segments
|
||||
* from this software for such purposes. Copyright of this software
|
||||
* remains with BladeX.
|
||||
* <p>
|
||||
* Using this software signifies agreement to this License, and the software
|
||||
* must not be used for illegal purposes.
|
||||
* <p>
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||
* not liable for any claims arising from secondary or illegal development.
|
||||
* <p>
|
||||
* Author: Chill Zhuang (bladejava@qq.com)
|
||||
*/
|
||||
package org.springblade.sharding.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.springblade.core.mp.base.BaseEntity;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 实体类
|
||||
*
|
||||
* @author Chill
|
||||
*/
|
||||
@Data
|
||||
@TableName("blade_notice")
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class Notice extends BaseEntity {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 租户ID
|
||||
*/
|
||||
@Schema(description = "租户ID")
|
||||
private String tenantId;
|
||||
|
||||
/**
|
||||
* 标题
|
||||
*/
|
||||
@Schema(description = "标题")
|
||||
private String title;
|
||||
|
||||
/**
|
||||
* 通知类型
|
||||
*/
|
||||
@Schema(description = "通知类型")
|
||||
private Integer category;
|
||||
|
||||
/**
|
||||
* 发布日期
|
||||
*/
|
||||
@Schema(description = "发布日期")
|
||||
private Date releaseTime;
|
||||
|
||||
/**
|
||||
* 内容
|
||||
*/
|
||||
@Schema(description = "内容")
|
||||
private String content;
|
||||
|
||||
|
||||
}
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
/**
|
||||
* BladeX Commercial License Agreement
|
||||
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||
* <p>
|
||||
* Use of this software is governed by the Commercial License Agreement
|
||||
* obtained after purchasing a license from BladeX.
|
||||
* <p>
|
||||
* 1. This software is for development use only under a valid license
|
||||
* from BladeX.
|
||||
* <p>
|
||||
* 2. Redistribution of this software's source code to any third party
|
||||
* without a commercial license is strictly prohibited.
|
||||
* <p>
|
||||
* 3. Licensees may copyright their own code but cannot use segments
|
||||
* from this software for such purposes. Copyright of this software
|
||||
* remains with BladeX.
|
||||
* <p>
|
||||
* Using this software signifies agreement to this License, and the software
|
||||
* must not be used for illegal purposes.
|
||||
* <p>
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||
* not liable for any claims arising from secondary or illegal development.
|
||||
* <p>
|
||||
* Author: Chill Zhuang (bladejava@qq.com)
|
||||
*/
|
||||
package org.springblade.sharding.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import org.springblade.sharding.entity.Notice;
|
||||
import org.springblade.sharding.vo.NoticeVO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Mapper 接口
|
||||
*
|
||||
* @author Chill
|
||||
*/
|
||||
public interface NoticeMapper extends BaseMapper<Notice> {
|
||||
|
||||
/**
|
||||
* 自定义分页
|
||||
*
|
||||
* @param page 分页
|
||||
* @param notice 实体
|
||||
* @return List<NoticeVO>
|
||||
*/
|
||||
List<NoticeVO> selectNoticePage(IPage page, NoticeVO notice);
|
||||
|
||||
}
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="org.springblade.sharding.mapper.NoticeMapper">
|
||||
|
||||
<!-- 通用查询映射结果 -->
|
||||
<resultMap id="noticeResultMap" type="org.springblade.sharding.entity.Notice">
|
||||
<result column="id" property="id"/>
|
||||
<result column="create_user" property="createUser"/>
|
||||
<result column="create_time" property="createTime"/>
|
||||
<result column="update_user" property="updateUser"/>
|
||||
<result column="update_time" property="updateTime"/>
|
||||
<result column="status" property="status"/>
|
||||
<result column="is_deleted" property="isDeleted"/>
|
||||
<result column="release_time" property="releaseTime"/>
|
||||
<result column="title" property="title"/>
|
||||
<result column="content" property="content"/>
|
||||
</resultMap>
|
||||
|
||||
<!-- 通用查询映射结果 -->
|
||||
<resultMap id="noticeVOResultMap" type="org.springblade.sharding.vo.NoticeVO">
|
||||
<result column="id" property="id"/>
|
||||
<result column="create_user" property="createUser"/>
|
||||
<result column="create_time" property="createTime"/>
|
||||
<result column="update_user" property="updateUser"/>
|
||||
<result column="update_time" property="updateTime"/>
|
||||
<result column="status" property="status"/>
|
||||
<result column="is_deleted" property="isDeleted"/>
|
||||
<result column="release_time" property="releaseTime"/>
|
||||
<result column="title" property="title"/>
|
||||
<result column="content" property="content"/>
|
||||
</resultMap>
|
||||
|
||||
<select id="selectNoticePage" resultMap="noticeVOResultMap">
|
||||
SELECT
|
||||
n.*,
|
||||
d.dict_value AS categoryName
|
||||
FROM
|
||||
blade_notice n
|
||||
LEFT JOIN ( SELECT * FROM blade_dict WHERE CODE = 'notice' ) d ON n.category = d.dict_key
|
||||
WHERE
|
||||
n.is_deleted = 0 and n.tenant_id = #{notice.tenantId}
|
||||
<if test="notice.title!=null">
|
||||
and n.title like concat(concat('%', #{notice.title}), '%')
|
||||
</if>
|
||||
<if test="notice.category!=null">
|
||||
and n.category = #{notice.category}
|
||||
</if>
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
/**
|
||||
* BladeX Commercial License Agreement
|
||||
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||
* <p>
|
||||
* Use of this software is governed by the Commercial License Agreement
|
||||
* obtained after purchasing a license from BladeX.
|
||||
* <p>
|
||||
* 1. This software is for development use only under a valid license
|
||||
* from BladeX.
|
||||
* <p>
|
||||
* 2. Redistribution of this software's source code to any third party
|
||||
* without a commercial license is strictly prohibited.
|
||||
* <p>
|
||||
* 3. Licensees may copyright their own code but cannot use segments
|
||||
* from this software for such purposes. Copyright of this software
|
||||
* remains with BladeX.
|
||||
* <p>
|
||||
* Using this software signifies agreement to this License, and the software
|
||||
* must not be used for illegal purposes.
|
||||
* <p>
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||
* not liable for any claims arising from secondary or illegal development.
|
||||
* <p>
|
||||
* Author: Chill Zhuang (bladejava@qq.com)
|
||||
*/
|
||||
package org.springblade.sharding.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import org.springblade.core.mp.base.BaseService;
|
||||
import org.springblade.sharding.entity.Notice;
|
||||
import org.springblade.sharding.vo.NoticeVO;
|
||||
|
||||
|
||||
/**
|
||||
* 服务类
|
||||
*
|
||||
* @author Chill
|
||||
*/
|
||||
public interface INoticeService extends BaseService<Notice> {
|
||||
|
||||
/**
|
||||
* 自定义分页
|
||||
* @param page
|
||||
* @param notice
|
||||
* @return
|
||||
*/
|
||||
IPage<NoticeVO> selectNoticePage(IPage<NoticeVO> page, NoticeVO notice);
|
||||
|
||||
}
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
/**
|
||||
* BladeX Commercial License Agreement
|
||||
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||
* <p>
|
||||
* Use of this software is governed by the Commercial License Agreement
|
||||
* obtained after purchasing a license from BladeX.
|
||||
* <p>
|
||||
* 1. This software is for development use only under a valid license
|
||||
* from BladeX.
|
||||
* <p>
|
||||
* 2. Redistribution of this software's source code to any third party
|
||||
* without a commercial license is strictly prohibited.
|
||||
* <p>
|
||||
* 3. Licensees may copyright their own code but cannot use segments
|
||||
* from this software for such purposes. Copyright of this software
|
||||
* remains with BladeX.
|
||||
* <p>
|
||||
* Using this software signifies agreement to this License, and the software
|
||||
* must not be used for illegal purposes.
|
||||
* <p>
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||
* not liable for any claims arising from secondary or illegal development.
|
||||
* <p>
|
||||
* Author: Chill Zhuang (bladejava@qq.com)
|
||||
*/
|
||||
package org.springblade.sharding.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import org.springblade.core.mp.base.BaseServiceImpl;
|
||||
import org.springblade.core.secure.utils.AuthUtil;
|
||||
import org.springblade.sharding.entity.Notice;
|
||||
import org.springblade.sharding.mapper.NoticeMapper;
|
||||
import org.springblade.sharding.service.INoticeService;
|
||||
import org.springblade.sharding.vo.NoticeVO;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 服务实现类
|
||||
*
|
||||
* @author Chill
|
||||
*/
|
||||
@Service
|
||||
public class NoticeServiceImpl extends BaseServiceImpl<NoticeMapper, Notice> implements INoticeService {
|
||||
|
||||
@Override
|
||||
public IPage<NoticeVO> selectNoticePage(IPage<NoticeVO> page, NoticeVO notice) {
|
||||
// 若不使用mybatis-plus自带的分页方法,则不会自动带入tenantId,所以我们需要自行注入
|
||||
notice.setTenantId(AuthUtil.getTenantId());
|
||||
return page.setRecords(baseMapper.selectNoticePage(page, notice));
|
||||
}
|
||||
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
package org.springblade.sharding.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.springblade.sharding.entity.Notice;
|
||||
|
||||
/**
|
||||
* 通知公告视图类
|
||||
*
|
||||
* @author Chill
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class NoticeVO extends Notice {
|
||||
|
||||
@Schema(description = "通知类型名")
|
||||
private String categoryName;
|
||||
|
||||
@Schema(description = "租户编号")
|
||||
private String tenantId;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
#不分库仅分表
|
||||
spring:
|
||||
#主数据源
|
||||
datasource:
|
||||
# MySql
|
||||
url: jdbc:mysql://localhost:3306/bladex?useSSL=false&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&serverTimezone=GMT%2B8&nullCatalogMeansCurrent=true&allowPublicKeyRetrieval=true
|
||||
username: root
|
||||
password: root
|
||||
#sharding数据源
|
||||
shardingsphere:
|
||||
datasource:
|
||||
#定义的数据库集合
|
||||
names: ds1
|
||||
#数据库连接别名
|
||||
ds1:
|
||||
#数据连接池类型
|
||||
type: com.alibaba.druid.pool.DruidDataSource
|
||||
#驱动类型
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
#jdbc地址
|
||||
url: jdbc:mysql://localhost:3306/bladex?useSSL=false&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&serverTimezone=GMT%2B8&nullCatalogMeansCurrent=true&allowPublicKeyRetrieval=true
|
||||
#数据库账号
|
||||
username: root
|
||||
#数据库密码
|
||||
password: root
|
||||
rules:
|
||||
sharding:
|
||||
#主键生成类型
|
||||
key-generators:
|
||||
snowflake:
|
||||
type: SNOWFLAKE
|
||||
tables:
|
||||
#分表代号
|
||||
blade_notice:
|
||||
#实际节点名称,格式为 库名$->{0..n1}.表名$->{0..n2}
|
||||
#blade_notice_$->{1..2} 代表有 blade_notice_1和blade_notice_2两个表
|
||||
actual-data-nodes: ds1.blade_notice_$->{1..2}
|
||||
#分表策略
|
||||
table-strategy:
|
||||
standard:
|
||||
#分表列名
|
||||
sharding-column: id
|
||||
#分表算法名,不可用下划线
|
||||
sharding-algorithm-name: blade-notice-inline
|
||||
#主键生成策略
|
||||
key-generate-strategy:
|
||||
#主键名
|
||||
column: id
|
||||
#策略算法
|
||||
key-generator-name: snowflake
|
||||
#分库分表算法
|
||||
sharding-algorithms:
|
||||
#分表算法名
|
||||
blade-notice-inline:
|
||||
#算法类型
|
||||
type: INLINE
|
||||
props:
|
||||
#算法表达式
|
||||
#表达式写法非常自由,以下配置仅作为参考
|
||||
#blade_notice_$->{id % 2 + 1} 代表对id进行取余,根据id的基偶来指向blade_notice_1和blade_notice_2
|
||||
algorithm-expression: blade_notice_$->{id % 2 + 1}
|
||||
@@ -0,0 +1,71 @@
|
||||
#不分表仅分库
|
||||
spring:
|
||||
#主数据源
|
||||
datasource:
|
||||
# MySql
|
||||
url: jdbc:mysql://localhost:3306/bladex?useSSL=false&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&serverTimezone=GMT%2B8&nullCatalogMeansCurrent=true&allowPublicKeyRetrieval=true
|
||||
username: root
|
||||
password: root
|
||||
#sharding数据源
|
||||
shardingsphere:
|
||||
datasource:
|
||||
names: ds1,ds2
|
||||
#数据库连接别名
|
||||
ds1:
|
||||
#数据连接池类型
|
||||
type: com.alibaba.druid.pool.DruidDataSource
|
||||
#驱动类型
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
#jdbc地址
|
||||
url: jdbc:mysql://localhost:3306/bladex1?useSSL=false&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&serverTimezone=GMT%2B8&nullCatalogMeansCurrent=true&allowPublicKeyRetrieval=true
|
||||
#数据库账号
|
||||
username: root
|
||||
#数据库密码
|
||||
password: root
|
||||
#数据库连接别名
|
||||
ds2:
|
||||
#数据连接池类型
|
||||
type: com.alibaba.druid.pool.DruidDataSource
|
||||
#驱动类型
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
#jdbc地址
|
||||
jdbc-url: jdbc:mysql://localhost:3306/bladex2?useSSL=false&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&serverTimezone=GMT%2B8&nullCatalogMeansCurrent=true&allowPublicKeyRetrieval=true
|
||||
#数据库账号
|
||||
username: root
|
||||
#数据库密码
|
||||
password: root
|
||||
rules:
|
||||
sharding:
|
||||
#主键生成类型
|
||||
key-generators:
|
||||
snowflake:
|
||||
type: SNOWFLAKE
|
||||
#默认分库策略
|
||||
default-database-strategy:
|
||||
standard:
|
||||
#列名
|
||||
sharding-column: id
|
||||
#算法名
|
||||
sharding-algorithm-name: database-inline
|
||||
tables:
|
||||
#表名代号
|
||||
blade_notice:
|
||||
#实际节点名称,格式为 库名$->{0..n1}.表名
|
||||
actual-data-nodes: ds$->{1..2}.blade_notice
|
||||
#主键生成策略
|
||||
key-generate-strategy:
|
||||
#主键名
|
||||
column: id
|
||||
#策略算法
|
||||
key-generator-name: snowflake
|
||||
#分库分表算法
|
||||
sharding-algorithms:
|
||||
#分库算法名
|
||||
database-inline:
|
||||
#算法类型
|
||||
type: INLINE
|
||||
props:
|
||||
#算法表达式
|
||||
#表达式写法非常自由,以下配置仅作为参考
|
||||
#ds$->{id % 2 + 1} 代表对id进行取余,根据id的基偶来指向 ds1和ds2
|
||||
algorithm-expression: ds$->{id % 2 + 1}
|
||||
@@ -0,0 +1,88 @@
|
||||
#分库+分表
|
||||
spring:
|
||||
#主数据源
|
||||
datasource:
|
||||
# MySql
|
||||
url: jdbc:mysql://localhost:3306/bladex?useSSL=false&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&serverTimezone=GMT%2B8&nullCatalogMeansCurrent=true&allowPublicKeyRetrieval=true
|
||||
username: root
|
||||
password: root
|
||||
#sharding数据源
|
||||
shardingsphere:
|
||||
datasource:
|
||||
names: ds1,ds2
|
||||
#数据库连接别名
|
||||
ds1:
|
||||
#数据连接池类型
|
||||
type: com.alibaba.druid.pool.DruidDataSource
|
||||
#驱动类型
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
#jdbc地址
|
||||
url: jdbc:mysql://localhost:3306/bladex1?useSSL=false&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&serverTimezone=GMT%2B8&nullCatalogMeansCurrent=true&allowPublicKeyRetrieval=true
|
||||
#数据库账号
|
||||
username: root
|
||||
#数据库密码
|
||||
password: root
|
||||
#数据库连接别名
|
||||
ds2:
|
||||
#数据连接池类型
|
||||
type: com.alibaba.druid.pool.DruidDataSource
|
||||
#驱动类型
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
#jdbc地址
|
||||
jdbc-url: jdbc:mysql://localhost:3306/bladex2?useSSL=false&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&serverTimezone=GMT%2B8&nullCatalogMeansCurrent=true&allowPublicKeyRetrieval=true
|
||||
#数据库账号
|
||||
username: root
|
||||
#数据库密码
|
||||
password: root
|
||||
rules:
|
||||
sharding:
|
||||
#主键生成类型
|
||||
key-generators:
|
||||
snowflake:
|
||||
type: SNOWFLAKE
|
||||
#默认分库策略
|
||||
default-database-strategy:
|
||||
standard:
|
||||
#列名
|
||||
sharding-column: id
|
||||
#算法名
|
||||
sharding-algorithm-name: database-inline
|
||||
tables:
|
||||
#分表代号
|
||||
blade_notice:
|
||||
#实际节点名称,格式为 库名$->{0..n1}.表名$->{0..n2}
|
||||
#ds$->{1..2}.blade_notice_$->{1..2} 代表有 ds1和ds2两个库以及blade_notice_1和blade_notice_2两个表
|
||||
actual-data-nodes: ds$->{1..2}.blade_notice_$->{1..2}
|
||||
#分表策略
|
||||
table-strategy:
|
||||
standard:
|
||||
#分表列名
|
||||
sharding-column: id
|
||||
#分表算法名,不可用下划线
|
||||
sharding-algorithm-name: blade-notice-inline
|
||||
#主键生成策略
|
||||
key-generate-strategy:
|
||||
#主键名
|
||||
column: id
|
||||
#策略算法
|
||||
key-generator-name: snowflake
|
||||
#分库分表算法
|
||||
sharding-algorithms:
|
||||
#分库算法名
|
||||
database-inline:
|
||||
#算法类型
|
||||
type: INLINE
|
||||
props:
|
||||
#算法表达式
|
||||
#表达式写法非常自由,以下配置仅作为参考
|
||||
#ds$->{id % 2 + 1} 代表对id进行取余,根据id的基偶来指向 ds1和ds2
|
||||
algorithm-expression: ds$->{id % 2 + 1}
|
||||
#分表算法名
|
||||
blade-notice-inline:
|
||||
#算法类型
|
||||
type: INLINE
|
||||
props:
|
||||
#算法表达式
|
||||
#表达式写法非常自由,以下配置仅作为参考
|
||||
#blade_notice_$->{id % 2 + 1} 代表对id进行取余,根据id的基偶来指向blade_notice_1和blade_notice_2
|
||||
algorithm-expression: blade_notice_$->{id % 2 + 1}
|
||||
@@ -0,0 +1,18 @@
|
||||
## server
|
||||
server:
|
||||
port: 8701
|
||||
|
||||
spring:
|
||||
#sharding通用配置
|
||||
shardingsphere:
|
||||
mode:
|
||||
#内存模式
|
||||
type: Standalone
|
||||
props:
|
||||
#是否展示sql
|
||||
sql-show: true
|
||||
blade:
|
||||
#开启分库分表自动配置
|
||||
#nacos会覆盖此配置,需要在nacos也配置为true
|
||||
sharding:
|
||||
enabled: true
|
||||
Reference in New Issue
Block a user