提交 439b22b1 authored 作者: Matrix's avatar Matrix

update kingdatabase config

上级 35bb5b29
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <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 https://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
...@@ -53,12 +53,6 @@ ...@@ -53,12 +53,6 @@
<artifactId>spring-boot-starter-freemarker</artifactId> <artifactId>spring-boot-starter-freemarker</artifactId>
</dependency> </dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency> <dependency>
<groupId>org.projectlombok</groupId> <groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId> <artifactId>lombok</artifactId>
...@@ -70,6 +64,21 @@ ...@@ -70,6 +64,21 @@
<artifactId>spring-boot-starter-test</artifactId> <artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<scope>compile</scope>
<groupId>com.baomidou</groupId>
<artifactId>dynamic-datasource-spring-boot-starter</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>com.kingdabe</groupId>
<artifactId>2</artifactId>
<version>2.3</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/lib/kingbase8-8.2.0.jar</systemPath>
</dependency>
</dependencies> </dependencies>
<build> <build>
...@@ -81,4 +90,4 @@ ...@@ -81,4 +90,4 @@
</plugins> </plugins>
</build> </build>
</project> </project>
\ No newline at end of file
...@@ -5,7 +5,11 @@ import org.springframework.boot.SpringApplication; ...@@ -5,7 +5,11 @@ import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication @SpringBootApplication
@MapperScan("com.matrix.md.sys.mapper") @MapperScan({
"com.matrix.md.sdb.mapper",
"com.matrix.md.xdb.mapper",
"com.matrix.md.ydb.mapper"
})
public class MybatisMutilDbApplication { public class MybatisMutilDbApplication {
public static void main(String[] args) { public static void main(String[] args) {
......
package com.matrix.md.sdb.controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.matrix.md.sdb.entity.User;
import com.matrix.md.sdb.mapper.SdbUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
/**
* <p>
* 前端控制器
* </p>
*
* @author matrix
* @since 2020-05-12
*/
@RestController
@RequestMapping("/sdb/user")
public class SdbUserController {
@Autowired
private SdbUserMapper userMapper;
@GetMapping
public ResponseEntity findUsers(){
return ResponseEntity.ok(userMapper.selectList(Wrappers.emptyWrapper()));
}
@PostMapping
public ResponseEntity insertUsers(@RequestBody User user) {
int i = userMapper.insert(user);
return ResponseEntity.ok(i);
}
}
package com.matrix.md.sdb.entity;
import java.io.Serializable;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
/**
* <p>
*
* </p>
*
* @author matrix
* @since 2020-05-12
*/
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@TableName(value = "SUSER")
public class User implements Serializable {
private static final long serialVersionUID = 1L;
private Long id;
private Integer age;
private String email;
private String name;
}
package com.matrix.md.sys.mapper; package com.matrix.md.sdb.mapper;
import com.matrix.md.sys.entity.User; import com.baomidou.dynamic.datasource.annotation.DS;
import com.matrix.md.sdb.entity.User;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.springframework.stereotype.Repository;
/** /**
* <p> * <p>
...@@ -9,8 +11,10 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; ...@@ -9,8 +11,10 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
* </p> * </p>
* *
* @author matrix * @author matrix
* @since 2020-05-11 * @since 2020-05-12
*/ */
public interface UserMapper extends BaseMapper<User> { @DS("sdb")
@Repository
public interface SdbUserMapper extends BaseMapper<User> {
} }
package com.matrix.md.sys.service; package com.matrix.md.sdb.service;
import com.matrix.md.sys.entity.User; import com.matrix.md.sdb.entity.User;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
/** /**
...@@ -9,8 +9,8 @@ import com.baomidou.mybatisplus.extension.service.IService; ...@@ -9,8 +9,8 @@ import com.baomidou.mybatisplus.extension.service.IService;
* </p> * </p>
* *
* @author matrix * @author matrix
* @since 2020-05-11 * @since 2020-05-12
*/ */
public interface IUserService extends IService<User> { public interface ISdbUserService extends IService<User> {
} }
package com.matrix.md.sys.service.impl; package com.matrix.md.sdb.service.impl;
import com.matrix.md.sys.entity.User; import com.matrix.md.sdb.entity.User;
import com.matrix.md.sys.mapper.UserMapper; import com.matrix.md.sdb.mapper.SdbUserMapper;
import com.matrix.md.sys.service.IUserService; import com.matrix.md.sdb.service.ISdbUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -12,9 +12,9 @@ import org.springframework.stereotype.Service; ...@@ -12,9 +12,9 @@ import org.springframework.stereotype.Service;
* </p> * </p>
* *
* @author matrix * @author matrix
* @since 2020-05-11 * @since 2020-05-12
*/ */
@Service @Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService { public class SdbUserServiceImpl extends ServiceImpl<SdbUserMapper, User> implements ISdbUserService {
} }
...@@ -52,11 +52,11 @@ public class CodeGenerator { ...@@ -52,11 +52,11 @@ public class CodeGenerator {
// 数据源配置 // 数据源配置
DataSourceConfig dsc = new DataSourceConfig(); DataSourceConfig dsc = new DataSourceConfig();
dsc.setUrl("jdbc:mysql://localhost:3306/md?serverTimezone=GMT%2B8"); dsc.setUrl("jdbc:mysql://192.168.1.100:3306/sdb?useSSL=false&serverTimezone=UTC&characterEncoding=utf-8");
// dsc.setSchemaName("public"); // dsc.setSchemaName("public");
dsc.setDriverName("com.mysql.cj.jdbc.Driver"); dsc.setDriverName("com.mysql.cj.jdbc.Driver");
dsc.setUsername("root"); dsc.setUsername("root");
dsc.setPassword("ldf3291369"); dsc.setPassword("123456");
mpg.setDataSource(dsc); mpg.setDataSource(dsc);
// 包配置 // 包配置
...@@ -90,6 +90,7 @@ public class CodeGenerator { ...@@ -90,6 +90,7 @@ public class CodeGenerator {
strategy.setNaming(NamingStrategy.underline_to_camel); strategy.setNaming(NamingStrategy.underline_to_camel);
strategy.setColumnNaming(NamingStrategy.underline_to_camel); strategy.setColumnNaming(NamingStrategy.underline_to_camel);
strategy.setEntityLombokModel(true); strategy.setEntityLombokModel(true);
strategy.setRestControllerStyle(true);
// strategy.setSuperControllerClass("com.baomidou.mybatisplus.samples.generator.common.BaseController"); // strategy.setSuperControllerClass("com.baomidou.mybatisplus.samples.generator.common.BaseController");
strategy.setInclude(scanner("表名")); strategy.setInclude(scanner("表名"));
strategy.setSuperEntityColumns("id"); strategy.setSuperEntityColumns("id");
......
package com.matrix.md.sys.controller; package com.matrix.md.xdb.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.matrix.md.sys.entity.User; import com.matrix.md.xdb.entity.User;
import com.matrix.md.sys.mapper.UserMapper; import com.matrix.md.xdb.mapper.XdbUserMapper;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RestController;
import java.util.List; import java.util.List;
/** /**
* <p> * <p>
* 前端控制器 * 前端控制器
* </p> * </p>
* *
* @author matrix * @author matrix
* @since 2020-05-11 * @since 2020-05-12
*/ */
@Controller @RestController
@RequestMapping("/sys/user") @RequestMapping("/xdb/user")
public class UserController { public class XdbUserController {
@Autowired @Autowired
private UserMapper userMapper; private XdbUserMapper userMapper;
@GetMapping @GetMapping
public ResponseEntity findUsers() { public ResponseEntity<List<User>> findUsers(){
LambdaQueryWrapper<User> query = Wrappers.lambdaQuery(); return ResponseEntity.ok(userMapper.selectList(Wrappers.emptyWrapper()));
query.ge(User::getAge, 18);
List<User> userList = userMapper.selectList(query);
return ResponseEntity.ok(userList);
} }
} }
package com.matrix.md.xdb.entity;
import java.io.Serializable;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
/**
* <p>
*
* </p>
*
* @author matrix
* @since 2020-05-12
*/
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
public class User implements Serializable {
private static final long serialVersionUID = 1L;
@TableId(type = IdType.AUTO)
private long id;
private Integer age;
private String email;
private String name;
}
package com.matrix.md.xdb.mapper;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.matrix.md.xdb.entity.User;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.springframework.stereotype.Repository;
/**
* <p>
* Mapper 接口
* </p>
*
* @author matrix
* @since 2020-05-12
*/
@DS("xdb")
@Repository
public interface XdbUserMapper extends BaseMapper<User> {
}
package com.matrix.md.xdb.service;
import com.matrix.md.xdb.entity.User;
import com.baomidou.mybatisplus.extension.service.IService;
/**
* <p>
* 服务类
* </p>
*
* @author matrix
* @since 2020-05-12
*/
public interface IXdbUserService extends IService<User> {
}
package com.matrix.md.xdb.service.impl;
import com.matrix.md.xdb.entity.User;
import com.matrix.md.xdb.mapper.XdbUserMapper;
import com.matrix.md.xdb.service.IXdbUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
/**
* <p>
* 服务实现类
* </p>
*
* @author matrix
* @since 2020-05-12
*/
@Service
public class XdbUserServiceImpl extends ServiceImpl<XdbUserMapper, User> implements IXdbUserService {
}
package com.matrix.md.ydb.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* <p>
* 前端控制器
* </p>
*
* @author matrix
* @since 2020-05-12
*/
@RestController
@RequestMapping("/ydb/user")
public class YdbUserController {
}
package com.matrix.md.sys.entity; package com.matrix.md.ydb.entity;
import java.io.Serializable; import java.io.Serializable;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors; import lombok.experimental.Accessors;
...@@ -11,18 +14,21 @@ import lombok.experimental.Accessors; ...@@ -11,18 +14,21 @@ import lombok.experimental.Accessors;
* </p> * </p>
* *
* @author matrix * @author matrix
* @since 2020-05-11 * @since 2020-05-12
*/ */
@Data @Data
@EqualsAndHashCode(callSuper = false) @EqualsAndHashCode(callSuper = false)
@Accessors(chain = true) @Accessors(chain = true)
public class User implements Serializable { public class User implements Serializable {
@TableId(type = IdType.AUTO)
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private String name;
private Integer age; private Integer age;
private String email;
private String name;
} }
package com.matrix.md.ydb.mapper;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.matrix.md.ydb.entity.User;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.springframework.stereotype.Repository;
/**
* <p>
* Mapper 接口
* </p>
*
* @author matrix
* @since 2020-05-12
*/
@DS("ydb")
@Repository
public interface YdbUserMapper extends BaseMapper<User> {
}
package com.matrix.md.ydb.service;
import com.matrix.md.ydb.entity.User;
import com.baomidou.mybatisplus.extension.service.IService;
/**
* <p>
* 服务类
* </p>
*
* @author matrix
* @since 2020-05-12
*/
public interface IYdbUserService extends IService<User> {
}
package com.matrix.md.ydb.service.impl;
import com.matrix.md.ydb.entity.User;
import com.matrix.md.ydb.mapper.YdbUserMapper;
import com.matrix.md.ydb.service.IYdbUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
/**
* <p>
* 服务实现类
* </p>
*
* @author matrix
* @since 2020-05-12
*/
@Service
public class YdbUserServiceImpl extends ServiceImpl<YdbUserMapper, User> implements IYdbUserService {
}
# DataSource Config
spring:
datasource:
dynamic:
primary: sdb # default datasource
strict: false #设置严格模式,默认false不启动. 启动后在未匹配到指定数据源时候回抛出异常,不启动会使用默认数据源.
datasource:
sdb:
driver-class-name: com.kingbase8.Driver
url: jdbc:kingbase8://192.168.1.245:54321/SDB
username: SYSTEM
password: qwer1234
xdb:
driver-class-name: com.kingbase8.Driver
url: jdbc:kingbase8://192.168.1.245:54321/XDB
username: SYSTEM
password: qwer1234
ydb:
driver-class-name: com.kingbase8.Driver
url: jdbc:kingbase8://192.168.1.245:54321/YDB
username: SYSTEM
password: qwer1234
\ No newline at end of file
# DataSource Config
spring:
datasource:
dynamic:
primary: sdb # default datasource
strict: false #设置严格模式,默认false不启动. 启动后在未匹配到指定数据源时候回抛出异常,不启动会使用默认数据源.
datasource:
sdb:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://192.168.1.100:3306/sdb?useSSL=false&serverTimezone=UTC&characterEncoding=utf-8
username: root
password: 123456
xdb:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://192.168.1.100:3306/xdb?useSSL=false&serverTimezone=UTC&characterEncoding=utf-8
username: root
password: 123456
ydb:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://192.168.1.100:3306/ydb?useSSL=false&serverTimezone=UTC&characterEncoding=utf-8
username: root
password: 123456
\ No newline at end of file
# DataSource Config
spring: spring:
datasource: profiles:
driver-class-name: org.h2.Driver active: kingbase
schema: classpath:db/schema-h2.sql
data: classpath:db/data-h2.sql
url: jdbc:h2:mem:test
username: root
password: test
logging: logging:
level: level:
com: com:
matrix: matrix:
md: md:
sys: sdb:
mapper: debug mapper: debug
\ No newline at end of file xdb:
mapper: debug
ydb:
mapper: debug
<?xml version="1.0" encoding="UTF-8"?> <?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"> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.matrix.md.sys.mapper.UserMapper"> <mapper namespace="com.matrix.md.sdb.mapper.SdbUserMapper">
</mapper> </mapper>
<?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="com.matrix.md.xdb.mapper.XdbUserMapper">
</mapper>
<?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="com.matrix.md.ydb.mapper.YdbUserMapper">
</mapper>
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论