mybatis-plus集成达梦数据库【其他数据库通⽤】⼀、POM⽂件,引⼊所需要的依赖
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.7.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.7.0</version>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.2.0</version>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-generator</artifactId>
<version>3.2.0</version>
</dependency>
<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
<version>2.3.29</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>5.2.0.RELEASE</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-test</artifactId>
</dependency>
</dependencies>
⼆、(配置)达梦的驱动包,配置数据源
在达梦数据库的安装⽬录下有驱动包,我们先把jar包丢进来,放到lib这个⽂件夹下:然后配置pom⽂件:
<dependency>
<groupId>com.dm</groupId>
<artifactId>Dm7JdbcDriver</artifactId>
<version>1.7</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/lib/Dm7JdbcDriver18.jar</systemPath>
</dependency>
三、配置法或者直接在实体类中调⽤
mybatis-plus:
mapper-locations: classpath:/mapper/*l
#实体扫描,多个package⽤逗号或者分号分隔
typeAliasesPackage: com.ity
typeEnumsPackage: com.ums
global-config:
# 数据库相关配置
db-config:
#主键类型  AUTO:"数据库ID⾃增", INPUT:"⽤户输⼊ID",ID_WORKER:"全局唯⼀ID (数字类型唯⼀ID)", UUID:"全局唯⼀ID UUID";
id-type: id_worker
#字段策略 IGNORED:"忽略判断",NOT_NULL:"⾮ NULL 判断"),NOT_EMPTY:"⾮空判断"
field-strategy: not_empty
#驼峰下划线转换
column-underline: true
#数据库⼤写下划线转换
#capital-mode: true
#逻辑删除配置
logic-delete-value: 0
logic-not-delete-value: 1
db-type: dm
#刷新mapper 调试神器
refresh: true
# 原⽣配置
configuration:
map-underscore-to-camel-case: true
cache-enabled: false
或直接在类中设置
private final static String SCHEMANAME = "SYSDBA";
private final static String DATAURL = "jdbc:dm://localhost:5236/WSDC?zeroDateTimeBehavior=convertToNull&useUnicode=true&characterEncoding=utf-8"; private final static String DRIVERNAME = "dm.jdbc.driver.DmDriver";
private final static String USERNAME = "WSDC";
private final static String PASSWORD = "123456789";
private final static String AUTHOR = "YHT";
private final static String[] TABLE_NAME = { "ZW_ALERTREVIEW" };
public static String scanner(String tip) {
Scanner scanner = new Scanner(System.in);
StringBuilder help = new StringBuilder();
help.append("请输⼊" + tip + ":");
System.out.String());
if (scanner.hasNext()) {
String ipt = ();
if (StringUtils.isNotEmpty(ipt)) {
return ipt;
}
}
throw new MybatisPlusException("请输⼊正确的" + tip + "!");
}
public static void main(String[] args) {
// 代码⽣成器
AutoGenerator mpg = new AutoGenerator();
// 全局配置
GlobalConfig gc = new GlobalConfig();
String projectPath = Property("user.dir");
gc.setOutputDir(projectPath + "/src/main/java")// ⽣成路径
.setFileOverride(true)//⽂件覆盖
.setServiceName("%sService") // 设置⽣成的service接⼝的名字的⾸字母是否为I
.setDateType(DateType.ONLY_DATE)
.setAuthor(AUTHOR)
.setOpen(false)
.setSwagger2(true)
//#主键类型  AUTO:"数据库ID⾃增", INPUT:"⽤户输⼊ID",ID_WORKER:"全局唯⼀ID (数字类型唯⼀ID)", UUID:"全局唯⼀ID UUID";
.setIdType(IdType.AUTO) // 主键策略
.setBaseResultMap(true)// ⽣成基本的resultMap
.setBaseColumnList(true);// ⽣成基本的SQL⽚段
// ⾃定义⽂件命名,注意 %s 会⾃动填充表实体属性!
// gc.setMapperName("%sDao");
// gc.setXmlName("%sMapper");
// gc.setServiceName("MP%sService");
// gc.setServiceImplName("%sServiceDiy");
// gc.setControllerName("%sAction");
mpg.setGlobalConfig(gc);
//达梦数据库的配置
DataSourceConfig dsc = new DataSourceConfig();
dsc.setDbType(DbType.DM);
dsc.setSchemaName(SCHEMANAME);
dsc.setUrl(DATAURL);
dsc.setDriverName(DRIVERNAME);
dsc.setUsername(USERNAME);
dsc.setPassword(PASSWORD);
mpg.setDataSource(dsc);
// 包配置
PackageConfig pc = new PackageConfig();
pc.setModuleName(scanner("模块名"))
.setMapper("mapper")// dao
.setService("service")// servcie
.
setController("controller")// controller
.setEntity("bean")
.setXml("mapper")// l
.setParent("com");
mpg.setPackageInfo(pc);
// ⾃定义配置
InjectionConfig cfg = new InjectionConfig() {
@Override
public void initMap() {
// to do nothing
}
};
spring framework jar包
List<FileOutConfig> focList = new ArrayList<>();
focList.add(new FileOutConfig("/l.ftl") {
@Override
public String outputFile(TableInfo tableInfo) {
// ⾃定义输⼊⽂件名称
return projectPath + "/src/main/resources/mapper/" + pc.getModuleName()
+ "/" + EntityName() + "Mapper" + StringPool.DOT_XML;
}
});
cfg.setFileOutConfigList(focList);
mpg.setCfg(cfg);
mpg.setTemplate(new TemplateConfig().setXml(null));
// 策略配置
StrategyConfig strategy = new StrategyConfig();
strategy.setNaming(NamingStrategy.underline_to_camel);
strategy.setColumnNaming(NamingStrategy.underline_to_camel);
strategy.setEntityLombokModel(true);
strategy.setInclude(TABLE_NAME); // 需要⽣成的表
//strategy.setSuperEntityColumns("id");//可去除实体类中ID
strategy.setControllerMappingHyphenStyle(true);// 驼峰转连字符
strategy.ModuleName() + "_");
strategy.setEntityLombokModel(true);
strategy.setSuperControllerClass("ller.BaseController");
//strategy.setSuperServiceClass("com.amazon.base.service.BaseService");
//strategy.setSuperServiceImplClass("com.amazon.base.service.impl.BaseServiceImpl");        //strategy.setSuperMapperClass("com.amazon.base.mapper.BaseMapper");
//strategy.setSuperEntityClass("com.del.BaseModel");
// strategy.setExclude(new String[]{"test"}); // 排除⽣成的表
// Boolean类型字段是否移除is前缀处理
// strategy.setEntityBooleanColumnRemoveIsPrefix(true)
//ityTableFieldAnnotationEnable(true);// 是否⽣成实体时,⽣成字段注解
//strategy.setLogicDeleteFieldName("createDate");
mpg.setStrategy(strategy);
// 选择 freemarker 引擎需要指定如下加,注意 pom 依赖必须有!
mpg.setTemplateEngine(new FreemarkerTemplateEngine());
}
都是开发,其他⾃⼰补充吧

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。