11package com .github .cadecode .uniboot .example .svc .controller ;
22
33import com .baomidou .dynamic .datasource .annotation .DS ;
4+ import com .github .cadecode .uniboot .common .plugin .datasource .config .ShardingJdbcConfig ;
45import com .github .cadecode .uniboot .framework .base .annotation .ApiFormat ;
6+ import com .github .cadecode .uniboot .framework .base .plugin .bean .po .PlgLog ;
7+ import com .github .cadecode .uniboot .framework .base .plugin .service .PlgLogService ;
8+ import com .github .pagehelper .PageHelper ;
59import io .swagger .annotations .Api ;
610import io .swagger .annotations .ApiOperation ;
711import lombok .RequiredArgsConstructor ;
1317import org .springframework .web .bind .annotation .RestController ;
1418
1519import java .sql .SQLException ;
20+ import java .util .List ;
1621
1722/**
1823 * dynamic-datasource 测试
2328@ ApiFormat
2429@ Slf4j
2530@ RequiredArgsConstructor
26- @ Api (tags = "dynamic-datasource 测试 " )
31+ @ Api (tags = "动态数据源测试 " )
2732@ DependsOn ("dataSource" )
2833@ RestController
2934@ RequestMapping ("demo/ds" )
@@ -34,6 +39,8 @@ public class DynamicDsController {
3439 */
3540 private final AbstractDataSource dataSource ;
3641
42+ private final PlgLogService plgLogService ;
43+
3744 @ DS ("master" )
3845 @ ApiOperation ("测试 master 数据源" )
3946 @ PostMapping ("test_master" )
@@ -48,4 +55,23 @@ public String testSlave1() throws SQLException {
4855 return dataSource .getConnection ().getMetaData ().getURL ();
4956 }
5057
58+ @ DS (ShardingJdbcConfig .SHARDING_DATA_SOURCE_NAME )
59+ @ ApiOperation ("测试 sharding 数据源读取" )
60+ @ PostMapping ("test_sharding_read" )
61+ public List <PlgLog > testShardingRead () throws SQLException {
62+ return PageHelper .startPage (0 , 10 )
63+ .<PlgLog >doSelectPageInfo (plgLogService ::list ).getList ();
64+ }
65+
66+ @ DS (ShardingJdbcConfig .SHARDING_DATA_SOURCE_NAME )
67+ @ ApiOperation ("测试 sharding 数据源写入" )
68+ @ PostMapping ("test_sharding_write" )
69+ public boolean testShardingWrite () throws SQLException {
70+ return plgLogService .save (PlgLog .builder ()
71+ .logType ("测试LOG" )
72+ .exceptional (false )
73+ .classMethod ("DynamicDsController.testShardingWriteAndRead" )
74+ .build ());
75+ }
76+
5177}
0 commit comments